Results 1 to 6 of 6

Thread: Identifying Clients

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    Identifying Clients

    Hello Everybody:

    I have created a multithreaded client server application...The server can received 50 client connections by creating new threads..The client uses there name and phone number as parameters to connect to the server...
    Now I want to send the information back to the same client
    from the server. My problem is identifying the correct client and sending the information to the correct client.
    I am identifying the client by using the GetHashCode method
    which will be generated by the name and phone number the client uses to login to the server.

    Now my problem is how do I use the Hashcode method which will be unique when I sent the information to the correct client..

    The code used to sent data to the client is as follows:


    try
    {
    Object objData = txtDataTx.Text;// the text box contains the data to be send....
    {
    byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString ());
    m_socWorker.Send (byData);
    }
    }
    catch(SocketException se)
    {
    MessageBox.Show (se.Message );
    }
    txtDataTx.Text="";


    I hope you guys can help me.I am stuck on this point..

    THanks,

    Kapil

  2. #2
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    Are you wanting to send the data back to the client as soon as you get it or are you storing the information an sending it later and are having problems identifying which client sent the which data?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    Identifying clients

    I am storing the information on the server(client name and phonenumber) in a ListView.I am having problems identifying the client and send the correct information to the correct client..

    Pls guide... I am stuck over here...

    Rahil


    Originally posted by Tewl
    Are you wanting to send the data back to the client as soon as you get it or are you storing the information an sending it later and are having problems identifying which client sent the which data?

  4. #4
    Addicted Member
    Join Date
    Jun 2003
    Location
    Birmingham, AL
    Posts
    188
    Well I usually write a class for the client sockets and store them in a hash table. It would be simple to store the information for each client in variables in the class then you could just cycle through the collection until you found the connection you were looking for. Thats just one way off the top of my head.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Feb 2004
    Posts
    97

    Identifying Clients

    Can you show an example.It will be helpful.

    Thanks,

    K

  6. #6
    Fanatic Member Redth's Avatar
    Join Date
    May 2001
    Location
    Ontario, Canada
    Posts
    551
    defenitley would say use a hashtable...

    when you accept the new connection put the socket into the hashtable with a new Guid as the key or something... then when you need to access that client, you just need the Guid, and you can recover the socket and send data back...

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