|
-
Mar 19th, 2004, 12:26 PM
#1
Thread Starter
Lively Member
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
-
Mar 19th, 2004, 12:54 PM
#2
Addicted Member
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?
-
Mar 19th, 2004, 01:04 PM
#3
Thread Starter
Lively Member
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?
-
Mar 19th, 2004, 03:50 PM
#4
Addicted Member
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.
-
Mar 19th, 2004, 04:50 PM
#5
Thread Starter
Lively Member
Identifying Clients
Can you show an example.It will be helpful.
Thanks,
K
-
Mar 20th, 2004, 12:08 PM
#6
Fanatic Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|