D
David
Hello
I'm using Sockets to send a receive data. My issue is when I open up a
socket, I can send and receive data correctly the first try. Upon the
second try without closing anything, I send some data, but receive nothing.
I noticed as I step through the code, during the second receive, I execute
the client.BeginReceive but the debugger goes to the next line without going
into the callback function, as if that Client.BeginRecieve line isn't there.
No errors occur.
Anyone have any ideas, what that maybe. Would I have some something blocking
from the first receive?
Below is some of the sample code I'm using.
// Create the state object.
StateObject state = new StateObject();
try
{
Socket client = Socket();
// Begin receiving the data from the remote device.
// issue a reset on a reset event
Reset();
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new
AsyncCallback(tcpct_ReceiveCallback), state);
// wait for completion up to 5 seconds
WaitOne(5000, false);
tcpct_RecieveCallback(IAsyncResult ar)
{
StateObject state = (StateObject)ar.AsyncState;
Socket client = Socket()
// Read data from the remote device.
int bytesRead = client.EndReceive(ar);
if (bytesRead > 0)
{
// There might be more data, so store the data received so far.
state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
// Get the rest of the data
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new
AsyncCallback(tcpct_ReceiveCallback), state);
}
I'm using Sockets to send a receive data. My issue is when I open up a
socket, I can send and receive data correctly the first try. Upon the
second try without closing anything, I send some data, but receive nothing.
I noticed as I step through the code, during the second receive, I execute
the client.BeginReceive but the debugger goes to the next line without going
into the callback function, as if that Client.BeginRecieve line isn't there.
No errors occur.
Anyone have any ideas, what that maybe. Would I have some something blocking
from the first receive?
Below is some of the sample code I'm using.
// Create the state object.
StateObject state = new StateObject();
try
{
Socket client = Socket();
// Begin receiving the data from the remote device.
// issue a reset on a reset event
Reset();
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new
AsyncCallback(tcpct_ReceiveCallback), state);
// wait for completion up to 5 seconds
WaitOne(5000, false);
tcpct_RecieveCallback(IAsyncResult ar)
{
StateObject state = (StateObject)ar.AsyncState;
Socket client = Socket()
// Read data from the remote device.
int bytesRead = client.EndReceive(ar);
if (bytesRead > 0)
{
// There might be more data, so store the data received so far.
state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
// Get the rest of the data
client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new
AsyncCallback(tcpct_ReceiveCallback), state);
}