Server and Client interactions

How should I handle interactions between the client and server. For example, instead of sending one giant heap of data all at once, I need a way for the client to request certain information at any time (at least, I think that’s how it should be done. Right?). Should I have a method that’d be something among the lines of:


final int MAP_DATA = 1,
          LIVE_ENTITIES = 2
          PLAYER_STATUS = 3;

void someClientMethod()
{
     ServerHandler.requestInformation(MAP_DATA);
}

and just have the server listen for the number that the client sends? I’m not really sure how I should do this, and I’m entirely new to networking. Any help/advice?

Geeze, one week and no replies in this whole forum…?

[quote]I need a way for the client to request certain information at any time (at least, I think that’s how it should be done. Right?)
[/quote]
You should send update packets. Neither the client or the server should ask the other one to send a specific packet. They just send their updates when needed. For example, when the player moves on the client it sends a MovementPacket to the server and the server send another packet to other connected clients to update the position. Your client shouldn’t ask for map data, but when your server updates the map it must send the update to the clients.
They just have to send the updates when they are generated, you don’t need to ask for any packet.

I suggest you to take a look at kryonet library. Its very simple to use but powerful and good for game programming. I like it very much and I’m using it for my current projects.

i guess we do not understand what you’re actually asking. the whoe networking topic is very broad.

usually we point into the http://www.kryonet.com/ direction and help you by saying “let this lib handle for you” but that could be not helping at all. i dont use kryo and could write a wall of text about what you could do cos’ there are so many things you can stack to get networking to work.

in general you’re right :

client sends specific message (for instance “request this and that”) -> server receives specific message -> mapps it to a action (and probalby applies some validation to the data) -> generates response -> wraps response in message -> sends message back -> client receives specific message -> mapps it to an action (and probably checks if and when it was requested or does other validation) -> executes action.

questions are : when do we send stuff at all, how do we convert (encode/decode or marshal/unmarshal) a message into/from the network-byte-stream. how do we map them to actions. how do we verify the message is valid within the context. … so many things to take care of.

i think you’re going into the right direction, how far did you get yet ?

ps: temu was faster :wink: