Hello. I already have winsock server and client programs. i have one server and about 10 clients.
What if the client and the server want to send a message to everyone connected to the server, how do i do it? Thanks guys!
Printable View
Hello. I already have winsock server and client programs. i have one server and about 10 clients.
What if the client and the server want to send a message to everyone connected to the server, how do i do it? Thanks guys!
Hi,
Ok, based on the fact you said client and server that leaves us one good way of doing this, and a method I commonly use.
The trick is to think of the server as a great big Satalite dish, and the clients as little transmitters, what happens is the client sends data to the server which simply, takes it process it if needed and then sends it back to every single client. So in your client you can continue to use the method,
VB Code:
Winsock.sendData myData
But your servers data arrival would be somthing like this,
VB Code:
Winsock(index).getData MyData Select Case left(1, mydata) Case "p" 'could mena anything means, they want to check for update or whatever 'parse that data here case else call SendToAll(MyData) end select
then you would need a simple routine to send data to all connected clients, and the code below will work great.
VB Code:
Public sub sendToAll(DataToSend as String) for i = 0 to winsock.ubound - 1 if winsock(i).state = sckconnected then winsock(i).senddata DataToSend end if doevents next i
With this kind of set up if you are sending lots and lots of data you may find the packets get caught up together. If this happens check out the link below!
http://www.vbforums.com/showthread.php?t=297570
http://winsockvb.com/article.php?article_id=26
Pino
Okay. I asked my project adviser about that and he said that when Client1 is connected to Server and Client2 is also connected to Server, Client1 and Client2 is already connected to each other, meaning Client1 can send data directly to Client2. Is this true?
No, I'm 99% certain he is wrong. The idea of a server is that every client connects to it. Your clients are not connected to each other.
Is this a programming adviser? If it was anyone else I would say they were daft, but maybe he knows somthing I dont know? But if we look at the set up, it isnt possible.
Pino
Nope. This is 110% wrong.
To do this Client1 MUST know Client2's IP address.
Pino suggested the best method I believe, however there is another way to do this.
When Client3 connects to the server, the server can send Client3 the IP addresses of client1 and client2. This now means that client 3 can talk directly with Client1 and 2.
I believe MSN Messenger uses this method when sending files to each other. U request the send, the server sends you the IP address of the target client. Your client then connects directly to target client and sends the file, which bypasses the MSN Server. Makes sense when using something like this on a massive scale.
Woka
Actually, that is what I suggested to him. Thanks to you I am ensured that I am right. Hehe.
Thanks for the reply guys!
Born out of CTCP and DCC from IRC going back many a year :)Quote:
Originally Posted by Wokawidget