ok here it is, I am basically teaching myself to program which is going so good so far.I am doing a client-server program which is just a basic chat and then i can move on from there and improve, probably use it in a game afterward.Now as I have never done something like this and to avoid reading a dozen books i need some quick tips and insights.

1. How should i handle the states of each client with the server?
-For instance, the client connects to my server and it registers
then logs into the chat.what i want to know what would be the
best way to tell the server that my client wants to register,
should I send a extra byte at the front of my packet to tell the
server this client wants to register.

2. Should i send all my register data in the same packet?
-Name and Password are both placed into the same packet
the server then dissects the packet and place the appropriate
information where it needs to be, I have done this method works
ok but wondering if there is a better way.

What other information can you give me, I am trying to keep it as basic as possible
I am using SDL/SDL_net/C++.

Recommended Answers

All 2 Replies

Before launching into the code, you need to decide on a protocol by which your client/server will communicate (and I don't just mean TCP or UDP). Which is exactly the question you've just asked in number one.

This is something only you can decide and it can be anything you want it to be typically (so long as it's feasible) for example. byte 1 = command byte, byte 2 = target length, byte 3 to targetlength + 3 = target etc.

The way you decide to do it is up to you and there's no "right" way to do it. Obviously the wrong way to do it, is to send 4Mb of data for a login command ;)

Number 2 is exactly the same thing. Just decide for yourself how you want to do it.

thanks for the reply, I came up with something seems to be working so far.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.