Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

How would I be able to send a class through the internet like this.

class Player
    public int Health;
    public Player Copy()
        return this;

And do this.

SendPacket(new Player);

Well something like that?

share|improve this question

closed as off topic by doppelgreener, ashes999, Josh Petrie, Byte56, Ricket Nov 12 '12 at 22:01

Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.

Look up serialization. – doppelgreener Nov 12 '12 at 10:10
Doh I didn't realize I was on the gamedev section. This question would be a better fit for since it is a general programming question not a game related question. However I can't flag it for move (has that been changed?). – Roy T. Nov 12 '12 at 10:17
@RoyT Pretty sure those kinds of flags just turn into close votes now. – doppelgreener Nov 12 '12 at 10:37

You have to do two things.

First you have to be able to serialize your object. The definition, according to MSDN is:

Serialization is the process of converting an object into a stream of bytes in order to store the object or transmit it to memory, a database, or a file. Its main purpose is to save the state of an object in order to be able to recreate it when needed. The reverse process is called deserialization.

You can find many ways to do this in C# but I would recommend to use the built in binary serialization techniques in .NET. You can start reading up on that here

Then you have to make some sort of connection. Between two computers. One way to do this is using sockets. Microsoft has made this quite easy in .NET (although I think in Java it is slightly easier but less flexible). To keep it simple I would suggest using Synchronous Sockets first. Synchronous means that the program 'hangs' until all the data has been received by the other party. See

If you don't want the program to hang while sending the data you can use Asynchronous Sockets. They are a lot harder to use because you have to explicitly tell the other end how much data to expect and you have to handle the several steps the sending takes. I found the MSDN tutorial on this a bit unclear but you can find them for client and server here and here. I also wrote my own tutorial which you can find here and if you try Google you will see there are a lot more so skim a few and then pick the one that you find explains it best.


  1. Serialize the object
  2. Send the bytes using a socket
  3. Receive the bytes on the other end
  4. Deserialize and we have reconstructed the object on another computer :)
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.