I have a C # network application in which many anonymous users connect to the game service.
Now I check the logs, and sometimes I see this exception:
[10:30:18.21352] 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 File.cs:line 141
This error comes from the NetworkStream object, now I'm trying to reproduce the problem, but how? How can I get this exception?
I tried to disconnect from myself, but it just gives a timeout, tried other things, but cannot make it work.
Maybe someone has an idea?
File contents:
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 (Exception ex)
{
Logger.LogException(ex);
}
finally
{
if (networkStream != null)
networkStream.Close();
if (session != null)
session.Disconnect();
}
}
source
share