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 Barcode else 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);
|