Advertisement

Identifying received data on server & server method calls

Started by June 14, 2017 11:18 PM
0 comments, last by djsteffey 7 years, 5 months ago
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.

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....

This topic is closed to new replies.

Advertisement