Skip to content
This repository has been archived by the owner on Oct 10, 2018. It is now read-only.

Commit

Permalink
Network revamp (WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
jmfranz committed May 1, 2018
1 parent 479e511 commit 1cc4ce7
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
13 changes: 10 additions & 3 deletions AnnelidaDispatcher/Model/DispatcherServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand Down
7 changes: 6 additions & 1 deletion AnnelidaDispatcher/Model/StateObject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
}
}

0 comments on commit 1cc4ce7

Please sign in to comment.