Question

I have the following data structure or record, which I need to stream to and from another machine through NetworkStream.

  TRemoteRecord = record
    command:TRemoteCommand;
    status:TRemoteStatus;
    signame:string;
    rvalue:double;
    ivalue:LongInt;
  end;

This is the way I am sending or writing data structure or record to the stream.

TheStream:NetworkStream;
 SignalClient:TcpClient;
 SignalServer:TcpServer;
 sb:TRemoteRecord;

 SignalClient.ConnectNew(LocalIPEdit.Text,Int32.Parse(ClientPort.Text));
 TheStream := new NetWorkStream(SignalClient.Connect.DataSocket);
 TheStream.Write(sb, 0 SizeOf(sb));

When I compile it, it raises an exception, "There is no overloaded write with these parameters."

How do you send and receive data structure or record through networkstream?

Thanks,

Was it helpful?

Solution

You need to serialize your Record first to a byte[].

This will get you started:

http://msdn.microsoft.com/en-us/library/ms752244.aspx

Here are two methods to serialize and deserialize a given type: http://dooba.net/2009/07/02/c-sharp-and-serializing-byte-arrays/ [NB: Pay special attention to how you handle the string (it has variable size) and your custom types.]

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top