C# send structure objects through socket
-
i have done a bit of reading in client/server programming in c#. i am familiar enough with this process to ask the following question: how do i transmit structure objects through tcp/ip instead of just strings? my app is a networked game with chat capabilities. so instead of just transmitting text, i would like to imploy a data structure or class structure that will have two fields: i. packet type ii. the data for the packet type and i would transmit this when needed during the execution of the application, and decode the data object at the receiving end and place it where it belongs. im not looking for code, just some ideas and search statements i can feed to google so i will; have a better understanding. ive read about serialisation/de serialisation, is that he way to go? thanks.
-
i have done a bit of reading in client/server programming in c#. i am familiar enough with this process to ask the following question: how do i transmit structure objects through tcp/ip instead of just strings? my app is a networked game with chat capabilities. so instead of just transmitting text, i would like to imploy a data structure or class structure that will have two fields: i. packet type ii. the data for the packet type and i would transmit this when needed during the execution of the application, and decode the data object at the receiving end and place it where it belongs. im not looking for code, just some ideas and search statements i can feed to google so i will; have a better understanding. ive read about serialisation/de serialisation, is that he way to go? thanks.
See serialization and deserialization of objects. I use BinaryFormatter for this job.
-
See serialization and deserialization of objects. I use BinaryFormatter for this job.
i just read the following: The Binary Formatter The Binary formatter provides binary encoding for compact serialization either for storage or for socket-based network streams. The BinaryFormatter class is generally not appropriate when data is meant to be passed through a firewall. -------------------- is Xml Serialization good for going through firewalls?
-
i just read the following: The Binary Formatter The Binary formatter provides binary encoding for compact serialization either for storage or for socket-based network streams. The BinaryFormatter class is generally not appropriate when data is meant to be passed through a firewall. -------------------- is Xml Serialization good for going through firewalls?
ikurtz wrote:
The BinaryFormatter class is generally not appropriate when data is meant to be passed through a firewall.
I don't see that in the documentation for the BinaryFormatter class[^] If you're using sockets, you already have an issue with firewalls. If you can connect the sockets, then the data you put over the wire isn't an issue - socket data is always binary. The binary formatter is for converting your objects to/from binary (binary serialization).
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
ikurtz wrote:
The BinaryFormatter class is generally not appropriate when data is meant to be passed through a firewall.
I don't see that in the documentation for the BinaryFormatter class[^] If you're using sockets, you already have an issue with firewalls. If you can connect the sockets, then the data you put over the wire isn't an issue - socket data is always binary. The binary formatter is for converting your objects to/from binary (binary serialization).
Mark Salsbery Microsoft MVP - Visual C++ :java:
-
i have done a bit of reading in client/server programming in c#. i am familiar enough with this process to ask the following question: how do i transmit structure objects through tcp/ip instead of just strings? my app is a networked game with chat capabilities. so instead of just transmitting text, i would like to imploy a data structure or class structure that will have two fields: i. packet type ii. the data for the packet type and i would transmit this when needed during the execution of the application, and decode the data object at the receiving end and place it where it belongs. im not looking for code, just some ideas and search statements i can feed to google so i will; have a better understanding. ive read about serialisation/de serialisation, is that he way to go? thanks.
As others said, you can use binary serialization to send data over the wire. But take a look at projects like Protocol Buffers[^] also. There is a .NET port available and it makes data transmission easy and it does serialization and deserialization for you.
Best wishes, Navaneeth