Results 1 to 2 of 2

Thread: Client Server Application-Modified

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    Client Server Application-Modified

    Hello Everybody:
    I have built a client server example using socket class where the server sends data to all the clients simultaneously. Now I want to send the data to that or one client when selected.. I have written the code to send the data to all clients. How do I modify the code so that I can select only each individual key to send the data to one client when selected...



    private void SendDataToAllClient(string str)

    {
    foreach (int sKey in socketHolder.Keys)

    {
    Socket s = (Socket)socketHolder[sKey];
    if(s.Connected)
    {
    Byte[] byteData = ASCII.GetBytes(str.ToCharArray());
    try
    {
    s.Send(byteData, byteData.Length, 0);
    }
    catch
    {
    // remove the bad client
    CloseTheThread(sKey);
    }
    }
    }

    Thanks,

    Kapil

  2. #2
    Frenzied Member Memnoch1207's Avatar
    Join Date
    Feb 2002
    Location
    DUH, Guess...Hint: It's really hot!
    Posts
    1,861
    You would need to know the Socket key you want to send to, then in the foreach loop just check if the key value matches the one you want to send it to.
    Being educated does not make you intelligent.

    Need a weekend getaway??? Come Visit

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