string IP = ConfigurationManager.AppSettings["ServerIP"].ToString();int Port = Convert.ToInt32(ConfigurationManager.AppSettings["Port"].ToString());int i = 0;do{string Barcode = lstBarcode.Items[i].ToString();txtResult.Text += GetTime() + " Barcode: " + Barcode + " scanned.";dbConnect.AddResponse(comIpAddress.SelectedItem.ToString(), Barcode, "Barcode scanned");//Gets random response, this will be replaced by server response. string barcode = "R1:" + txtBarcode.Text + "\r";TcpClient clientSocket = new TcpClient();clientSocket.Connect(IP, Port);NetworkStream serverStream = clientSocket.GetStream();byte[] outStream = Encoding.ASCII.GetBytes(barcode);serverStream.Write(outStream, 0, outStream.Length);serverStream.Flush();byte[] inStream = new byte[10025];serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);string returndata = System.Text.Encoding.ASCII.GetString(inStream);returndata = returndata.Remove(6);if (returndata == "I1:005"){txtResult.Text += GetTime() + " Barcode: " + Barcode + " had not enough points.";dbConnect.AddResponse(comIpAddress.SelectedItem.ToString(), Barcode, "Barcode Ignored");returndata = "";}//Open Barcodeelse if (returndata == "G1:005"){txtResult.Text += GetTime() + " Opening gate for barcode: " + Barcode;dbConnect.AddResponse(comIpAddress.SelectedItem.ToString(), Barcode, "Barcode Success");returndata = "";}i++;} while (i <count);
[15:40:21:265] Program started.[15:40:23:687] Added 3 Barcodes[15:40:24:734] Barcode: 4113530275052234 scanned.[15:40:25:437] Opening gate for barcode: 4113530275052234[15:40:25:437] Barcode: 4335964778311252 scanned.[15:40:26:46] Barcode: 7771230666718299 scanned.
[15:40:21:265] Program started.[15:40:23:687] Added 3 Barcodes[15:40:24:734] Barcode: 4113530275052234 scanned.[15:40:25:437] Opening gate for barcode: 4113530275052234[15:40:25:437] Barcode: 4335964778311252 scanned.[15:40:26:46] Opening gate for barcode: 4335964778311252[15:40:26:46] Barcode: 7771230666718299 scanned.[15:40:27:257] Opening gate for barcode: 7771230666718299