Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Reply
 
Thread Tools Display Modes
  #1  
Old 03-18-2005, 06:28 AM
sadavis80 sadavis80 is offline
Junior Member
 
Join Date: Mar 2005
Posts: 4
Default How to determine which socket connection belongs to which client?

I have mulitple clients connecting to a single server (TWinSocket components in D6). There SHOULD be a way to determine which client is which in the ServerSockClientRead event so that independent text buffers can be maintained. HOW?? I can't find any way short of iterating through all open connections for every event. That is WAY too much overhead!

There must be a pointer to "this" active connection - please tell me there is...
Client1
Client2
Client3
...
ServerSockClientRead
s := Socket.ReceiveText;
Which Client sent s?

tia,
Steve
Reply With Quote
  #2  
Old 03-18-2005, 07:13 AM
mibrani mibrani is offline
Junior Member
 
Join Date: Mar 2005
Posts: 21
Default RE: How to determine which socket connection belongs to which client?

Hi,

You can tell who sent the buffer/text by getting the IP address of the sender which is accomplished using the following code :

Sender.RemoteAddress

I hope I was helpful
Reply With Quote
  #3  
Old 03-18-2005, 07:58 AM
sadavis80 sadavis80 is offline
Junior Member
 
Join Date: Mar 2005
Posts: 4
Default RE: How to determine which socket connection belongs to which client?

Thanks mibrani but, unfortunately, that doesn't solve my problem. I want to know which ActiveConnection (.connections[x]) is the one I'm receiving. I'm trying to avoid a stringcompare (to match the IP address) and substitute an integer compare instead to determine the sender.

It's incredibly hard for me to believe that I can't identify the 'connection' value from within the ClientRead event - but I can't seem to find a way to do it.

I can use your suggestion (already do) in the OnConnect event to identify the 'connector', but don't want to have to do that string compare again for every message received from LOTS of senders. String compares are very expensive in terms of CPU time compared to integer compares.

Steve
Reply With Quote
  #4  
Old 03-20-2005, 11:53 PM
mibrani mibrani is offline
Junior Member
 
Join Date: Mar 2005
Posts: 21
Default RE: How to determine which socket connection belongs to which client?

Steve,

If you can't do IP address(string) compare which is in anyway the most error free and reliable method then you can send a "tag" number from client and then read it from server so that you can identify the client.
Reply With Quote
  #5  
Old 03-21-2005, 04:10 AM
sadavis80 sadavis80 is offline
Junior Member
 
Join Date: Mar 2005
Posts: 4
Default RE: How to determine which socket connection belongs to which client?

Mibrani,
Thanks - I can use that for most of the comms (don't know why I didn't think of that). It won't identify the client in OnConnect or OnDisconnect, but I don't mind doing the string compare in those cases :-).

Steve
Reply With Quote
  #6  
Old 03-24-2005, 07:23 AM
sadavis80 sadavis80 is offline
Junior Member
 
Join Date: Mar 2005
Posts: 4
Default RE: How to determine which socket connection belongs to which client?

mibrani - and anyone else who might care :-)
I did finally solve my problem by delving into the VCL. I grabbed the ScktComp.pas module and then added an integer property to the TCustomWinSocket class that I could use to hold the index to an array. I make the search in 'OnConnect' and write the array value. Then in 'Read' I just access the value to determine the Client. It works perfectly.

I still can't understand why it wasn't part of the original component.

Hopefully someone else can use this info.

Steve
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 05:15 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.