N
Niklas
I'm having a problem with the TCPClient/NetworkStream that I can't get
around. When I send something on the socket I don't know if it's
received by the server or not. I always get IsCompleted. IsCompleted
== true no matter if the server receives the packet or not. After 2
minutes I get the socket timeout if the server is unreachable.
I know the following:
SetSocketOption – Send timeout is not implemented on Win CE
The default Send timeout is 2 minutes
I can use socket Keep Alive but that affects all sockets on the system
The commonly suggested solution:
Use a timer to se if there is a pending message.
Let the server send a response for each packet. (We use GPRS and would
like to keep the network traffic to a minimum)
My question is:
How can I see if a socket (or NetworkStream) has a pending packet?
Some how the network layer knows it since it reports it after 2
minutes.
Thanx,
Niklas
//TcpClient m_tcpClient;
private void Send()
{
try
{
string tmpString = "Hello";
Encoding encStr = Encoding.Default;
Byte[] ByteGet = encStr.GetBytes(tmpString);
m_tcpClient.BeginSend(ByteGet, 0, ByteGet.Length,
0, new AsyncCallback(SendMsgCallBack),
new SentMsgStatStruct(m_tcpClient, tmpString));
}
catch( Exception exc )
{
MessageBox.Show("Exception: " + exc.ToString());
}
}
private void SendMsgCallBack(System.IAsyncResult ar)
{
try
{
MessageBox.Show("Completed: " + ar.IsCompleted.ToString());
MessageBox.Show("Completed Sync: " +
ar.CompletedSynchronously.ToString());
socket.EndSend(ar);
}
catch( SocketException e )
{
MessageBox.Show("Socket exception: " + e.ToString());
}
catch( Exception exc )
{
MessageBox.Show("Exception: " + exc.ToString());
}
}
around. When I send something on the socket I don't know if it's
received by the server or not. I always get IsCompleted. IsCompleted
== true no matter if the server receives the packet or not. After 2
minutes I get the socket timeout if the server is unreachable.
I know the following:
SetSocketOption – Send timeout is not implemented on Win CE
The default Send timeout is 2 minutes
I can use socket Keep Alive but that affects all sockets on the system
The commonly suggested solution:
Use a timer to se if there is a pending message.
Let the server send a response for each packet. (We use GPRS and would
like to keep the network traffic to a minimum)
My question is:
How can I see if a socket (or NetworkStream) has a pending packet?
Some how the network layer knows it since it reports it after 2
minutes.
Thanx,
Niklas
//TcpClient m_tcpClient;
private void Send()
{
try
{
string tmpString = "Hello";
Encoding encStr = Encoding.Default;
Byte[] ByteGet = encStr.GetBytes(tmpString);
m_tcpClient.BeginSend(ByteGet, 0, ByteGet.Length,
0, new AsyncCallback(SendMsgCallBack),
new SentMsgStatStruct(m_tcpClient, tmpString));
}
catch( Exception exc )
{
MessageBox.Show("Exception: " + exc.ToString());
}
}
private void SendMsgCallBack(System.IAsyncResult ar)
{
try
{
MessageBox.Show("Completed: " + ar.IsCompleted.ToString());
MessageBox.Show("Completed Sync: " +
ar.CompletedSynchronously.ToString());
socket.EndSend(ar);
}
catch( SocketException e )
{
MessageBox.Show("Socket exception: " + e.ToString());
}
catch( Exception exc )
{
MessageBox.Show("Exception: " + exc.ToString());
}
}