Ok I fixed it but still have a little problem: Agent Log:
Sent notification to server that we were about to send 20230 bytes
Transferred the following actions to server: SERVICES,
Server Log:
[12/2/2010 9:48:56 AM]: -- 192.168.1.163:21064 has connected to the server
[12/2/2010 9:48:56 AM]: 192.168.1.163:21064 is about to send 20230 bytes
[12/2/2010 9:48:56 AM]: Finished receiving 8760 bytes from 192.168.1.163:21064
[12/2/2010 9:48:56 AM]: Agent 192.168.1.163:21064 sent back null
[12/2/2010 9:48:56 AM]: Finished sending 118 bytes to 192.168.1.163:21064
So as you can see the agent is sending all the data, but the server is only getting 8760 bytes? Why is the server not reading all of the data? State Object:
public Socket worker = null;
public int BufferSize = 4;
public byte\[\] buffer;
public MemoryStream ms = new MemoryStream();
Server:
int bytesRead = handler.EndReceive(iar);
if (bytesRead > 0)
{
if (state.BufferSize == 4)
{
state.BufferSize = BitConverter.ToInt32(state.buffer, 0);
state.buffer = new byte[state.BufferSize];
Logging.Log(handler.RemoteEndPoint.ToString() + " is about to send " + state.BufferSize.ToString() + " bytes", true);
handler.BeginReceive(state.buffer, 0, state.BufferSize, 0,
new AsyncCallback(ReadCallback), state);
}
else
{
state.ms.Write(state.buffer, 0, bytesRead);
Logging.Log("Finished receiving " + state.ms.Length.ToString() + " bytes from " +
handler.RemoteEndPoint.ToString(), true);
// All data has been received from client
state.ms.Seek(0, SeekOrigin.Begin);
IFormatter formatter = new BinaryFormatter();
object receivedObject = null;
try
{
receivedObject = formatter.Deserialize(state.ms);
}
catch (SerializationException se)
{
Logging.Log("Object passed was not capable of being deserialized. Error: " + se.ToString(), false);