I have a method that is a listener for a TCP client that looks like this:
private static void ProcessClient(
Object obj)
{
ISession session = (ISession)obj;
NetworkStream networkStream = null;
try
{
DebugUtility.SetThreadName("Worker: {0}", session.Name);
networkStream = session.TcpClient.GetStream();
networkStream.ReadTimeout = Config.ReadTimeout;
Int32 packetSize;
Byte[] buffer = new Byte[session.PacketSize];
while ((packetSize = networkStream.Read(buffer, 0, buffer.Length)) != 0)
{
String packet = Encoding.UTF8.GetString(buffer, 0, packetSize);
if (String.IsNullOrEmpty(packet))
continue;
DebugUtility.CheckMaxPacketSize(session.Name, packet.Length);
Logger.DebugLog("Received: {0}", packet);
ThreadPool.QueueUserWorkItem(session.HandlePacket, packet);
}
}
catch (ObjectDisposedException) { }
catch (NotSupportedException) { }
catch (TimeoutException) { }
catch (SocketException) { }
catch (IOException) { }
catch (Exception ex)
{
Logger.LogException(ex);
}
finally
{
if (networkStream != null)
networkStream.Close();
if (session != null)
session.Disconnect();
}
}
This is for the game service, but when I check my logs, I sometimes see this error:
System.Int32 Read(Byte[], Int32, Int32): The stream does not support reading.
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at BusinessLayer.Listener.ListenerWorker.ProcessClient(Object obj) in C:\path\ListenerWorker.cs:line 141 Line: 0
This is the above file and line 141
while ((packetSize = networkStream.Read(buffer,....
Now I found that a NotSupportedException throws this error, but why does it go away? Why is it not ignored, but does it go through a regular Exception ex-handler?
Edit: Does anyone know how I can raise this exception? When does this happen? I see that it is returning to my logs to other users, but I do not know when this will happen.
source
share