Sign in to follow this  
viki26

making connection between 2 clients

Recommended Posts

hello, I have written a server that accepts connections with clients. (In c++ for windows). now I want to take 2 clients and create a connection between them. can anyone help me with that? how do I do it? thank you, Viki

Share this post


Link to post
Share on other sites
There are two ways of doing this. One is an actual connection and the other on is a virtual one.

Making the actual on your just give the client the ability to accept incoming connections. Once you do that you tell the other client to connect. The same as you did with your server.

The other way, and the one that I suggest is having all the data pass through the server. This means that you really don't need to directly connect to the other client and that you don't have to do anything else then what is already done in the way of connections.

You create a packet type that is a client-to-client message. When the server sees this message it just sends in on to the appropriate client. It is the way that I do all of my "client-to-client" communications.

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
There are two ways of doing this. One is an actual connection and the other on is a virtual one.

Making the actual on your just give the client the ability to accept incoming connections. Once you do that you tell the other client to connect. The same as you did with your server.

The other way, and the one that I suggest is having all the data pass through the server. This means that you really don't need to directly connect to the other client and that you don't have to do anything else then what is already done in the way of connections.

You create a packet type that is a client-to-client message. When the server sees this message it just sends in on to the appropriate client. It is the way that I do all of my "client-to-client" communications.

theTroll


I tohught about the second one, but when I have thousends of connections that the srever needs to deal with, I don't wish to "slow" its work by giving it more assignments as transfering packets from one client to another.
the problem with the first suggestion is this- at the end of the comunication of the 2 clients, I want the server to get a report about the clients' conversation - how can it be done? and is this method safe? (hacking etc...)

and thanks for your help!

Share this post


Link to post
Share on other sites
Having the communications pass through the sever is not going to be as big as hit at you think it will be. I am guessing this is just chat messages of some sort and not game play messages. Because humans really can't type that fast, there will not be so many messages that your server is going to be hurt by them. If you want the sever to have a record of the messages, you are either going to have to have the server get a copy of the message when the conversation is done, or have it updated each time a message is sent between the clients. If you notice you are sending the excact same amount of information to the server, the only differnce is the server is not having to send the information back out.

With what you are wanting to do, I think the best solution is to let your server take care of all the messages. It gives you a single point of control and also allows for filtering or anything else you want done. I also don't think it is a good idea to connect two clients dirrectly because then you are "giving" the ip address of the other client to an outside client. Not really a good idea, a person could come on and connect to each client and aquire all of the ip addresses from each client and then try to attack the clients if they wanted to.

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
Having the communications pass through the sever is not going to be as big as hit at you think it will be. I am guessing this is just chat messages of some sort and not game play messages. Because humans really can't type that fast, there will not be so many messages that your server is going to be hurt by them. If you want the sever to have a record of the messages, you are either going to have to have the server get a copy of the message when the conversation is done, or have it updated each time a message is sent between the clients. If you notice you are sending the excact same amount of information to the server, the only differnce is the server is not having to send the information back out.

With what you are wanting to do, I think the best solution is to let your server take care of all the messages. It gives you a single point of control and also allows for filtering or anything else you want done. I also don't think it is a good idea to connect two clients dirrectly because then you are "giving" the ip address of the other client to an outside client. Not really a good idea, a person could come on and connect to each client and aquire all of the ip addresses from each client and then try to attack the clients if they wanted to.

theTroll



well, actually, it's not a chat messege, it is a game messege. (2 clients playing with each other, and the server needs to know at the end of the game what happened at the game - who won, how many points etc....). and there are many "couples" of clients playing with each other.... so you see my problem...

Share this post


Link to post
Share on other sites
When I am talking about "game" mesasges, I am talking about very time dependent messages, like moves, actions, things like that.

Just sending the results of the game, points and things like that is a very trival message. I still recomend going through the server.

What kind of game is this?

theTroll

Share this post


Link to post
Share on other sites
Quote:
Original post by TheTroll
When I am talking about "game" mesasges, I am talking about very time dependent messages, like moves, actions, things like that.

Just sending the results of the game, points and things like that is a very trival message. I still recomend going through the server.

What kind of game is this?

theTroll




It's a board game. but you recomend to transfer all the moves through the server. that would be ok if there was only 1 game at a time, but I want many games to be handeled at the same time. I don't see how the server can handle them all.... (and at the same time get new connections).

I realy appriciate your help,
Viki.

Share this post


Link to post
Share on other sites
Since it is only a board game the traffic is going to be very small. A server can handle a thousand clients sending hundreds of message per minute if it done right, so doing a borad game with just a few moves is not really going to be much of a load at all.

The trick to doing this is making sure you are handling the connection in a non-blocking way, threads and callbacks. This will make it so the server is not holding off connections while processing something else. Any server would be up to doing this.

theTroll

Share this post


Link to post
Share on other sites
from the Wiki: a callback is executable code that is passed as an argument to other code. It allows a low level software layer to call a function occurring in a higher level layer. Usually the higher level code first calls a function within the lower level code passing to it a pointer or handle to another function. Then the lower level function in the course of executing may call the passed-in function any number of times to perform some subtask. Another option is that the lower level function registers the passed-in function as a handler that is to be called asynchronously by the lower level at a later time in reaction to something.

The big key here is that it can be called asynchronously and this avoids blocking. Blocking is when your code prevents anything else from happening until it is completed. When dealing with network traffic blocking is bad because you will not be able to process incomming traffic or connection if your code is blocked. By using a callback the incomming traffic will be processed but will not block new traffic from arriving.

theTroll

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