diff --git a/AnnelidaDispatcher/Model/DispatcherServer.cs b/AnnelidaDispatcher/Model/DispatcherServer.cs index 4388959..85c664f 100644 --- a/AnnelidaDispatcher/Model/DispatcherServer.cs +++ b/AnnelidaDispatcher/Model/DispatcherServer.cs @@ -134,10 +134,9 @@ public void ReadHandler(IAsyncResult ar) Socket handler = state.WorkSocket; // Read data from the client socket. - int bytesRead = 0; try { - bytesRead = handler.EndReceive(ar); + state.RecvBytesCount = handler.EndReceive(ar); } //TODO: handle disonnection messages (SHUTODOWNMODES) catch(SocketException e) @@ -155,9 +154,17 @@ public void ReadHandler(IAsyncResult ar) state = null; } + if(state?.RecvBytesCount <=0) + return; + + if (state.RecvBytesCount == 4) + { + state + } + //if our client has not identified itself the first //message he sends is his ID - if (state != null && (bytesRead > 0 && !state.IsInitialized)) + if (state != null && (state.RecvBytesCount > 0 && !state.IsInitialized)) { //We are expecting and int representing the client type diff --git a/AnnelidaDispatcher/Model/StateObject.cs b/AnnelidaDispatcher/Model/StateObject.cs index 0231dad..c7046d8 100644 --- a/AnnelidaDispatcher/Model/StateObject.cs +++ b/AnnelidaDispatcher/Model/StateObject.cs @@ -45,11 +45,16 @@ public class DispatcherClientObject public DispatcherClientObject() { //Uppon init we expect and int32 - BufferSize = 4; + BufferSize = 8192; RecvBytesCount = 0; IsInitialized = false; Buffer = new byte[BufferSize]; MyType = ClientTypes.Types.Undefined; } + + public void ResetBuffer() + { + Buffer = new byte[BufferSize]; + } } }