|
-
Jan 4th, 2006, 10:52 PM
#1
Thread Starter
Addicted Member
[RESOLVED] SendingAMessageToMultiplePC
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!
-
Jan 6th, 2006, 10:31 AM
#2
Re: SendingAMessageToMultiplePC
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,
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
-
Jan 10th, 2006, 12:38 AM
#3
Thread Starter
Addicted Member
Re: SendingAMessageToMultiplePC
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?
-
Jan 10th, 2006, 04:30 AM
#4
Re: SendingAMessageToMultiplePC
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
-
Jan 10th, 2006, 09:16 AM
#5
Re: SendingAMessageToMultiplePC
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
-
Jan 11th, 2006, 06:48 PM
#6
Thread Starter
Addicted Member
Re: SendingAMessageToMultiplePC
Actually, that is what I suggested to him. Thanks to you I am ensured that I am right. Hehe.
Thanks for the reply guys!
-
Jan 11th, 2006, 07:07 PM
#7
Retired VBF Adm1nistrator
Re: SendingAMessageToMultiplePC
 Originally Posted by Wokawidget
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.
Born out of CTCP and DCC from IRC going back many a year
Microsoft MVP : Visual Developer - Visual Basic [2004-2005]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|