T
tantiboh
I'm not a new programmer, but this one's got me stymied; hopefully it's a fairly trivial problem.
I'm using a socket connection to receive communication from a server. Normally, the entire message is received before the program moves on with its next instructions. However, at times when the processor is particularly busy the program seems to progress with its instructions without having received the entire communication. In other words, it seems to clean out the buffer, which due to the computer's business is holding only the first packet at this point, then move on without waiting for the buffer to fill with the next packet.
Is there a way to stop the program until it has been told that the entire communication has been received? Or a way to iteratively receive the packets until the program is told the communication is finished?
Here's my code:
IPHostEntry IPAdd = Dns.Resolve("servername.com");
//Configure the socket
IPEndPoint IPEP = new IPEndPoint(IPAdd.AddressList[0], 2628);
Socket s = new Socket(IPEP.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
//Construct the message
string str = "Message"
//Declare the receive buffer. Maximum of 50,000 characters.
Byte[] Receiver = new Byte[50000];
//Connect the socket
s.Connect(IPEP);
//Receive greeting. Is discarded.
Int32 bytes = s.Receive(Receiver, Receiver.Length, 0);
//Declare the send buffer. Initialize it with the query, converted into bytes.
Byte[] Sender = System.Text.Encoding.ASCII.GetBytes(str);
//Send the query.
s.Send(Sender, Sender.Length, 0);
//Receive the response into the byte array
bytes = s.Receive(Receiver, Receiver.Length, 0);
//Translate the byte array into ASCII text
strResponse = System.Text.Encoding.ASCII.GetString(Receiver, 0, bytes);
....Furthur code
Thanks for your help!
**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...
I'm using a socket connection to receive communication from a server. Normally, the entire message is received before the program moves on with its next instructions. However, at times when the processor is particularly busy the program seems to progress with its instructions without having received the entire communication. In other words, it seems to clean out the buffer, which due to the computer's business is holding only the first packet at this point, then move on without waiting for the buffer to fill with the next packet.
Is there a way to stop the program until it has been told that the entire communication has been received? Or a way to iteratively receive the packets until the program is told the communication is finished?
Here's my code:
IPHostEntry IPAdd = Dns.Resolve("servername.com");
//Configure the socket
IPEndPoint IPEP = new IPEndPoint(IPAdd.AddressList[0], 2628);
Socket s = new Socket(IPEP.Address.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
//Construct the message
string str = "Message"
//Declare the receive buffer. Maximum of 50,000 characters.
Byte[] Receiver = new Byte[50000];
//Connect the socket
s.Connect(IPEP);
//Receive greeting. Is discarded.
Int32 bytes = s.Receive(Receiver, Receiver.Length, 0);
//Declare the send buffer. Initialize it with the query, converted into bytes.
Byte[] Sender = System.Text.Encoding.ASCII.GetBytes(str);
//Send the query.
s.Send(Sender, Sender.Length, 0);
//Receive the response into the byte array
bytes = s.Receive(Receiver, Receiver.Length, 0);
//Translate the byte array into ASCII text
strResponse = System.Text.Encoding.ASCII.GetString(Receiver, 0, bytes);
....Furthur code
Thanks for your help!
**********************************************************************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...