Sign in to follow this  
Nalda

Identifying received data on server & server method calls

Recommended Posts

Nalda    103
Hi there, after 2 days of unfruitful researching, I finally sell my soul and ask for once

I'm just starting out in socket programming (C#)
All I managed to do for now is calling a method with BeginReceive and its async callback parameter.

What I'm trying to get my head around, is, how do you actually call a specific method depening on the data received ?

Note that I didn't get any further yet than just displaying the received bytes as a string.

Share this post


Link to post
Share on other sites
ncsu121978    1344

you need to decide what the data in the packet means to your game.  the format of the packet.  you will want something like that first byte being an identifier for what kind of data follows.  then based on the byte you know what to do with the rest of the data in the packet.

 

i.e.

the first byte is a 0 which means it is a chat message.  you then read out the next bytes that represent the message and then display that message on the screen.

the first byte is a 1 which means it is a position update message.  you then read out the next bytes that represent an object id and position.  you then move the object with the id and set its position.

the first byte is a 2 which means is a "fire ze missiles" message.  you then read out the next bytes that represent the id of the object that fired the missile, the start position of the missile, and the vector of its movement.  you then call your method to add a new missile to your game.

etc....

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this