Results 1 to 7 of 7

Thread: [RESOLVED] SendingAMessageToMultiplePC

  1. #1

    Thread Starter
    Addicted Member bulletrick's Avatar
    Join Date
    Jul 2005
    Location
    Philippines
    Posts
    248

    Resolved [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!

  2. #2
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    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,

    VB Code:
    1. Winsock.sendData myData

    But your servers data arrival would be somthing like this,

    VB Code:
    1. Winsock(index).getData MyData
    2.  
    3. Select Case left(1, mydata)
    4.        Case "p"
    5.          'could mena anything means, they want to check for update or whatever
    6.          'parse that data here
    7.        case else
    8.            call SendToAll(MyData)
    9. 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:
    1. Public sub sendToAll(DataToSend as String)
    2.  
    3. for i = 0 to winsock.ubound - 1
    4.  
    5. if winsock(i).state = sckconnected then
    6.       winsock(i).senddata DataToSend
    7. end if
    8.  
    9. doevents
    10. 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

  3. #3

    Thread Starter
    Addicted Member bulletrick's Avatar
    Join Date
    Jul 2005
    Location
    Philippines
    Posts
    248

    Question 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?

  4. #4
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    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

  5. #5
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632

    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

  6. #6

    Thread Starter
    Addicted Member bulletrick's Avatar
    Join Date
    Jul 2005
    Location
    Philippines
    Posts
    248

    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!

  7. #7
    Retired VBF Adm1nistrator plenderj's Avatar
    Join Date
    Jan 2001
    Location
    Dublin, Ireland
    Posts
    10,359

    Re: SendingAMessageToMultiplePC

    Quote 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
  •  



Click Here to Expand Forum to Full Width