Hi Dw.

I'm creating a multi-client/server program. I have developed both client and server the server will connect up to 3 clients simultaneously and each client may send an action request to a server at anytime and the server should be able to reply to only that particular client, at the moment suppose I'm having this hard coded: a clients will send a username and will wait a bit so that a server will receive the username and assign it to a variable then the client again will send the password up on receiving the password same process will take place where the server will assign the password to another variable to free up the variable I used to read the dataArival so that the data won't be mixed up, up on receiving (now note this the server here should like use an ip combined with port number for client to keep track of the client sending the data so that the clients data won't be mixed, will be easily tracked, suppose after client 1 sent a username then client let's say 2 sends its username to the server, at the moment the server will take the client2's username as a client1's password and will assign it as a password so what I want is that it should detect that now client2 has sent its username so it should also assign the client2's username on another variable for client2 username while still waiting for client1's password, and client2's password too.)

Now when these data has been received the server then try to match with the server side entered credentials then send back the response, suppose client1 sent the matching credentials so the server should send to client1 the text "ok" since its only client1 that has sent a correct or matching credentials so its must only be client1 that will receive the message "ok" and because client2 didn't match should receive "fail" and only client2 should receive this message so at the moment the respond from a server is broad casted to every client connected but I only want to send a corresponding message to a corresponding client at a corresponding time.

I don't know how I can do this, the idea I thought of was to simply use the IP together with port numbers to send data but I failed to understand how to send a message to a client using its IP &Port number using winsock.

Thank you.

I've managed to solve this problem. For someone who mite experience the same problem, the solution is, you need to index the socket threads as each thread will handle each client. To brake it down, when a client connects to a server you need to index that client so that you will have a sort of array clients on one winsock control so to be able to send messages to a particular client only no matter how many clients are connected, you need to send the response within the DataArrival block at least worked for me and you need to send the message like this:

 Winsock1(Index).SendData("your data here")

The (Index) will send the message to the requested client only.

Here is the perfect link for this:


Be a part of the DaniWeb community

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