Hi Dw.

I'm developing a Client Server application. At the moment I can connect the two and send data. The main aim is to make a server as a core control. The server only perform actions according to each client request, so the client can request to connect to let say "@Bob" where in my database on the first time "@Bob" initialized a connection with a server he registered a username "@Bob" and the server will capture the IP address of "@Bob" as well as the username "@Bob" and registered it on a database so that when let say "@John" wants to connect with "@Bob" can type in a textbox like this "connect @Bob" then when the server receive this message the server will then look in to a database in searching for a username "@Bob" and if the username is found then the server will retrieve the IP Address of "@Bob" then use it to send a message to "@Bob" that "@John" wants to connect with him, I will stop there because the only part I want to know is how to connect to a client using an IP address.

I must say this, the clients will in most cases be always connected to server so the server will only use the IP to check if the desired client is still available or reachable, then the server will send a message notifying the contacted client that there is someone contacting him/her then if the contacted clients accepts this request then the server should be like a bridge, receive data and send it between the two while the two are still connected but I mainly want to send data between the two once they are connected to make it a more real time response.

My point is how can I send a message and connect two clients to send data between them, the server is only a connector. At the moment I can respond to each client.

I think that you have pretty much answered your question yourself already.
If you can send data between the client and server, then the server knows the IP of the client, right?
And also, because you can send data to the server it's quite easy to send a command the server can respond to.
Just add code to read/write the database with the requested username as an argument and start a new thread that communicates with the requested second client, if online.

Threads in VB.NET can be made to talk to each other, so shuffling data between the two (or three or four) is possible in order to allow communication between two clients with the server as the go-between.
There are many examples and tutorials, both here and other sites, that can show you how to accomplish this.
Like this one: Share Information Between Threads

Thanks but, what I'm trying to say is that the server knows the clients IP address because I use "Client(index)" to support multiple clients, but now let's say there are 10 clients connected and client1 wants to connect with client10 so the server already know all of the connected clients but to enable client1 to communicate with client10 they need to connect, so these clients IP addresses will be saved on a database then when the client request to be connected with another client, the server will retrieve the clients IP and connect them up, the data that is sent between these two clients must not be sent to a server it must be between these clients that had been connected up, but the server should be able to take control between these clients, meaning the server must also be able to cut connection between the two at some point.

The server will be the middleware and connector too.

I think I need to try simplifying this. Suppose I have 10 clients that are connected to a server. NOTE1: A client can send data to a server and a server can respond to that "particular client".

So suppose Client1 want to send let's say a 'private' message to Client10, so because this message is private it must only be received by Client10 because the message was sent to him.

So firstly how can I achieve that? This is more similar to what I asked before just that now it will be the server that will deal with locating the contacted clients and the clients should be able to send data between them only no other client to receive that message. NOTE2: The message is not from the server it from

  Client1 ------- Server ------- Client10

Ok I won't complicate this now. That's what I want to achieve.

By using the server as the initial connector between clients and then handing it off to the clients themselves to "talk", you may not be able to have the server restablish control and break the connection.

Your best bet is, as I said, to have the server be the constant relay.
Also, unless you store/log the communications between the clients then all data transfers are private. Considering that the communication also is semi peer-to-peer.
You also might wanna implement some kind of client-side encryption/decryption to ensure that, should the clients wish to go private.
Using a pre-defined random key sent by the requesting client, you can ensure that the recieving client decrypts the data correctly.

The use of Client(index) tells me that you have a fixed array of client IP's.
It needs to be a by-command dynamic call to the datasource, and you only need to remember the client requesting the peer-to-peer connection and the client-requestee.

Ok this now just sound more complex, as you said if the server establish connection and handing over to the clients to communicate the server won't have any control of cutting the connection, just thought but I don't know if its possible, suppose 'Client1' is connected and are exchanging messages with 'Client10' and the server come to a point where it must cut the connection between these clients, since the server won't have any control of cutting the connection, is it possible that a server can send a message to a client that requested this connection or the client that requested to be connected with another client, the server will send a message to this client to cut immediately the connection between the connected client and free up every used stream?

I just looked also at peer to peer but didn't find an article that I could understand on how to send data to a particular client from another client.

I thought this was gonna be easy but now it seem difficult. Only if I can be able to send data from a particular client to another client I think that will help, will have to deal with how the server can control the connection between these clients later.

I saw another post where it was suggested to use the MeshTable and the use of Usernames to identify the target client, the other article which is a WCF used something which was interesting, the Author said the client also acts as a server too, so in his article he also created a method of retrieving or getting all connected computers and populate it to a combobox so that each client can select which target to communicate with or is targeted to receive the message, so this at some points sound as similar to what I'm trying to achieve except that on that post you need to select the name from a combobox but I want the user to type something like this: '@Boh' where '@Boh' is username which is a computer let say the original computer name is : 'Steve-PC' and this '@Boh' is a username that will be also matched in a database to be able to retrieve the target computer name which in this case is 'Steve-PC' and this will be resolved to get the IP address of this computer and the message can be sent from let's say Client1 with username '@Alice' and computer name 'John-PC' and the server is just a server maybe located at computer name 'BlueSky-PC'.

So as you can see the data should be sent from or between the clients, from a client to a client (p2p) but it must not be broad casted to all the clients.

The article that I'm talking about is located here:

mobile.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/A_11178-A-Peer-To-Peer-LAN-Chat-Application-in-Visual-Basic-Net-using-TcpClient-and-TcpListener.html

Consider this, two clients are merrily talking to each other. How and when would the server know when to cut the connection?

Odd that you did'nt find any articles at all.
Most articles out there describes how it's done. Listen and send. That's peer-to-peer.
All those types of clients that you can download has that built-in. They listen for an incoming handshake connection, send a response, listen for data, send data.
The server is, sort of, also a peer-to-peer client but with the ability to recieve commands on which it can act on.

Here's a good example of a peer-to-peer solution: http://www.codeproject.com/Articles/1297/Peer-to-Peer-Communicator-and-File-Transfer

Here's a good video tutorial of a client-server solution: https://www.youtube.com/watch?v=MSiBbtxWpI8
He mentions's that the list of clients can come from any type of collection.
For me, that includes a database.

Here's a sample multi-user client server solution: https://code.msdn.microsoft.com/Simple-Multi-User-TCPIP-1ff0da41

Good luck! :)

Thanks, just to answer your question on how and when will a server knows when to cut a connection, the server will keep some essential details of the clients like for instance the counts(time) the client is given to communicate with another client, so let's say the client now has (1925) so for each interval or timer tick while the client is in communication (connected) with another client the server will do the count down from the contactor time so when the count reaches (0) then the server should cut immediately the connection and drop all message packets that were sent between the two.

So that's how a server know when to stop the connection so that because clients may share large files so that will also have its own time given just like (Data bundles) and that will be counted per each KB/MB sent as well as received too so that the clients can be controlled on the connection time, they must not connect for too long.

Thanks will look at the links then will get back as soon as I'm done looking at them.

Yeah. My question was retorical. :)
The reason I asked was, if you manage to use the server to initialize the communication and then release it into the hands of the clients, then the server would no longer know anything about what's going on between the clients and thus not know when to kill the connection.
But, if you keep the server as a relay and force the clients to communicate through the server, then you can use those countdown timers. :)

Ok. But I'm a bit not sure if I keep the server as relay, if the communication between clients will be in real time.

In my opinion it's a bit hard to define "real time" as an actual amount of time.
How would you know the difference between 0.00 seconds and 5 seconds since you're not talking to yourself, nor may the other client not even be in the same building/room as yours.
Especially when text-chatting.

Yeah I think that will be a problem, but I think (note sure if its possible) to let the server as a relay be the one that gets the time its received the data from let's say Client1 and send it to the desired client which in this case is Client10 then the client10 will then send maybe a message (R) for received then the server will then send this to client1 to notify the sender that his/her data was successfully sent and has been received.

I think this will help so that the server will compare the time it sent the data and the time its received the response and I will have to write this to a log file for now to check the speed in different network connectivity.

I'm not entirely sure if it's possible to have it both ways.
Allow the server to maintain the established connection between each client talking to each other, but to also establish a direct connection between the clients for sending of messages.

That would permit the server to run that connection timer and send instructions to each client ordering them to terminate the connection to each other. And also for the clients to have that close-to-real-time communication you want.
But it requires each client to run two threads, one listening to the server and the other for talking to the other client.

@Oxiegen, I think you are right. A server can be a relay if client1 wants to send data to client10 this will go through server maybe with a username to be sent to like"To:@Alice-(data)" then the username will be resolved by server to get the ip for client10 or locate ip for client10 from the collection then the server send data to client10 with a client1 username like "From:@Bob-(data)", only in server the usernames/IPs will be resolved vise verse ( if the message contains Ip then that Ip will be resolved to correct Username, if its username then the username will be resolved to Ip)

The problem is to send this messages to their directed targets within this 10 clients and also not broadcasting it to all by only the targeted client.

Ok Thanks to everyone. When I was developing another client server chat app I came across an answer to this problem. The solution is that you are able to send data to a computer/client by specifying the target ip address. For locating the user that's a servers job and the server will look for that username the user wish to contact and within that user record in the database it will look for the ip address field and retrieve that and send it to that client requesting it. This is like, The first client will enquire the server to where the second client is contacted then a server will look that from the database then send that contact ip to the requesting client.

As for termination the server will also look for the requesting client balance from the database then send that if that client has enough balance then the connection will be permited and a duration will also be sent to the client. The client will then attempt to connect to that client and once connected the client will then be connected for the stated duration.

This question has already been answered. Start a new discussion instead.