Reputation: 315
I tried to send it from one client to another, and the source, destination and the data receive fine, but the string and the double become null. This is the code of the TcpObject
:
[Serializable]
public class TcpObject
{
public Command Command { set; get; }
public Object Data { set; get; }
public int Source { set; get; }
public int Destination { set; get; }
public string IDString { set; get; }
public double exactTime { set; get; }
public TcpObject()
{
Command = Command.Null;
Data = null;
}
This is where I send the data:
TcpObject tcpObject = new TcpObject();
tcpObject.Command = Command.Msg;
tcpObject.Source = 1;
tcpObject.Destination = 2;
byte[] junkMsg = new byte[1000];
tcpObject.Data = junkMsg;
tcpObject.IDString = randomString();
tcpObject.exactTime = exactTime.ExactTime();
WorkClient.Send(tcpObject);
hread.Sleep(20);
And this is where I receive:
public void Listen()
{
try
{
while (Connected)
{
TcpObject tcpObject = new TcpObject();
IFormatter formatter = new BinaryFormatter();
tcpObject = (TcpObject)formatter.Deserialize(ServerSocket);
MessageBox.Show(tcpObject.IDString);
//TcpObject succeedTcpObject = new TcpObject();
//get the remainder of the time that the message got send and when the message got accepted.
}
}
catch (Exception) { }
}
This is the send function:
public static void Send(TcpObject tcpObject)
{
try
{
IFormatter formatter = new BinaryFormatter();
formatter.Serialize(ServerSocket, tcpObject);
}
catch (Exception) { }
}
The MessageBox that pops up is empty. I checked before I sent the msg and the string was present.
Thanks.
Upvotes: 0
Views: 67
Reputation: 9430
Obviously, you send garbage that is never initialized:
byte[] junkMsg = new byte[1000];
tcpObject.Data = junkMsg;
--SNIP--
WorkClient.Send(tcpObject);
Upvotes: 1