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?
|
How would I be able to send a class through the internet like this.
And do this.
Well something like that? |
|||||||||||
|
Questions on Game Development Stack Exchange are expected to relate to game development within the scope defined in the FAQ. 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 closed questions here.
|
You have to do two things. First you have to be able to serialize your object. The definition, according to MSDN is:
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 http://msdn.microsoft.com/en-us/library/vstudio/ms233843.aspx 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 http://msdn.microsoft.com/en-us/library/6xt5x5zw.aspx 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. Recap
|
|||
|
|