Lex

Lex

  • NA
  • 20
  • 0

Do while loop error

Jun 23 2010 10:49 AM

I've currently got this code running:
 

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

and this is the output:
 

[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. 

My problem is the that solution should be looking like this:
 

[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

As  you can see, after sending the first one, get the response, it only sends the next barcodes, it doesn't recieve an answer from the server.
Can anyone see where I go Wrong?

Answers (1)