Sign in to follow this  
Alex_H

Basic Network help.

Recommended Posts

Hello All. I am currently in the process of learning Network code required for my course. And are in the process of creating a basic chat program. I have learnt and used code taken from http://www.gametutorials.com/ and have a simple chat client/server set up. However I have reached a point where my understanding has ended and I need a bit of help. So far my code as it stands, allows any number of Clients to connect to the server. They can send a message to the server, and the server returns the message directly back to the client. However I want this "message" to be sent to all the clients currently connected. I believe my problems comes from the threads that the tutorials uses. The code uses a threads to monitor the port, creating a new one each time a client connects. Handling them through a Mutex. However my problem now comes trying to get the different threads to "talk" to one another. Having never used threads before Im not sure how to acomplish this. Anyhelp with this would be appreciated. -Alex

Share this post


Link to post
Share on other sites
Well it is clear I feel that I wont be able to over come this problem when it comes to the threads.

However looking around the net and here in the forums is that there is little help for TCP/IP networking in c++ for multiple clients. Is this truely the case?

I fully admit that I am not a good programmer and I need alot fo help in how to do this. I can create, bind, listen/connect send/recv and close sockets.

However when I come to handling multiple clients my brain just gets fried. I understand the theory behind it all, but implementing it, I just havent got a clue.

I have begun to rewrite my code, ignore the threads parts, however I am finding it hard to implement the whole select() FD_SET etc etc. Does anyone know of a good tutorial... or could help me out in learning it?

All the examples I find are either in java or C, and I get confused when reading them.

-Alex

Share this post


Link to post
Share on other sites
hi Alex,

you might want to consider using a different API then winsock. for example, a higher level API such as Raknet. an API like raknet takes care of these low level things such as threading, managing connections etc. also, raknet will take it a step further and provide you help with more advanced, game specific things such as synchronizing time on all clients and a distributed object system. if you dont feel confident, and dont care about the low level stuff, i would definetly check out raknet. it makes things like managing connections transparent for you..

good luck in whatever you do.

Share this post


Link to post
Share on other sites
<I believe my problems comes from the threads that the tutorials uses. The code uses a threads to monitor the port, creating a new one each time a client connects. Handling them through a Mutex. However my problem now comes trying to get the different threads to "talk" to one another. Having never used threads before Im not sure how to acomplish this. >

Are you saying you create a new thread per client?

If you are then this is a bad idea.

You need a listening socket on its own thread yes, but you should put all (or large groups) of clients on another single thread.

check out this piece:
http://www.codersource.net/winsock_tutorial_server_select_model.html

stick with it, it will come to you in the end.

As for using Raknet or other API's, I wouldnt bother (especially since your learning this stuff ona course). Doing this stuff isnt that bad once you get over the first steps (it just gets more complicated as you need to manage your secket sets/threads etc). Using these API's means you dont know whats going on, and they are only wrappers for the winsock stuff anyway.


Share this post


Link to post
Share on other sites
well, the one advantage of using a high level API is time. personally, im working on a persistant MORPG by myself. i've been working on it everday for a little over 7 months, and am just now finishing things like database setup, login and account creation, etc..

if i had to use winsock, i would have had to learn the lower level syntax, would have had to write my own reliability layer, my own time synchronization system, my own connection management system, my own cross-platform wrapper functions, etc... i just don't have the time to do this since i want to finish the game withint 10 years [smile].

anyway, the point is, yes, its nice to understand and write all your low level code from scratch. but if someone has already done it for you, and its tested, i dont see any need in doing it myself, given my project scope and timeline.

Share this post


Link to post
Share on other sites
Yes, I know what your saying, especially in the way of security features some of these API's handle.

I was talking from the standpoint of the original poster, who is learning networking as part of a course.

So how is the game going? I have recently besome interested in online RPG's and thinking of starting to write the client/server sides.

Share this post


Link to post
Share on other sites
hey Dot,

your right, since the whole reason he is doing this is to learn, then yeah, learning sockets might be a good idea. however if he wanted to actually make a game, i would jump right into using a higher level lib, unless maybe he was on a team of other people..

my game is coming along good, slowly but surely [smile].

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