Results 1 to 7 of 7

Thread: how to send message to all client??

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Resolved how to send message to all client??

    how to send message to all client connects to server?
    Last edited by kenny_oh; Oct 7th, 2005 at 07:45 AM.

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: how to send message to all client??

    You can use the DOS command - "NET Send * This is the message"
    or did you need something more elaborate?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: how to send message to all client??

    i'm using winsock.....so every time server send message to all client, it only need to send one time .......can my idea work? simlar to socket broadcast function

  4. #4
    I don't do your homework! opus's Avatar
    Join Date
    Jun 2000
    Location
    Good Old Europe
    Posts
    3,863

    Re: how to send message to all client??

    In what way do you ue Winsock?
    If it's TCP you have to send each client a message, since you need to have one WinSock- TCP connection for each client.
    Using the UDP Protokol you can have all clients listening and the server has to send only once. But each Client has to be listening!
    You're welcome to rate this post!
    If your problem is solved, please use the Mark thread as resolved button


    Wait, I'm too old to hurry!

  5. #5
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: how to send message to all client??

    I do this in one of my apps. More or less it goes like this: When a client connects, I add the Socket to a Hashtable. To send a message to all clients, loop through the Hashtable, pull out the Socket, and send your message.

    Mike

  6. #6

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2005
    Posts
    840

    Re: how to send message to all client??

    put socket in hashtable?

  7. #7
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    Re: how to send message to all client??

    Quote Originally Posted by kenny_oh
    put socket in hashtable?
    Yes. You could use any sort of collection that can accept an object.

    I use a Hashtable because my message definition contains a user ID. So I store the user ID as the key, and the Socket as the value. If you don't need to store the user ID or can't retrieve it from messages, you probably don't need a Hashtable - an array of objects might work too.

    The idea is that you have a collection of all the Sockets that belong to the clients, then you can just iterate through the Socket collection and send a message.

    Here's a code snippet from a test I did a couple years ago - it has flaws like no error handling, it's using the synchronous .Send method, and the for...each could be improved, but hopefully it gives you the idea.

    VB Code:
    1. Private Sub SendMessageToClients(ByVal message As String)
    2.     Try
    3.         Dim myDE As DictionaryEntry
    4.         Dim s As Socket
    5.         For Each myDE In serverSockets ' serverSockets is a Hashtable
    6.             s = myDE.Value
    7.             s.Send(Encoding.ASCII.GetBytes(message))
    8.         Next
    9. End Sub
    Mike

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