[twsocket] TWSocket and Client number

2011-01-18 Thread daniel cc
Hello,
What do I need to do to get the client number into the server?

As you can see here,
I get the computer’s name, IP and Port but the client number is missing.
---
procedure TSimpleSslServerForm.SslWSocketServer1ClientConnect(
Sender : TObject;
Client : TWSocketClient;
Error  : Word);
begin
with Client as TTcpSrvClient do begin
Display('['+ GetComputerName + ']'+ //here we are getting the client 
number.
'Client connected.' +
' Remote: ' + PeerAddr + '/' + PeerPort +
' Local: '  + GetXAddr + '/' + GetXPort);
Display('There is now ' +
IntToStr(TWSocketServer(Sender).ClientCount) +
' clients connected.');
LineMode:= True;
LineEdit:= True;
LineLimit   := 80; { Do not accept long lines }
OnDataAvailable := ClientDataAvailable;
OnLineLimitExceeded := ClientLineLimitExceeded;
OnBgException   := ClientBgException;
OnSslVerifyPeer := ClientVerifyPeer;
ConnectTime := Now;
end;
end;
---
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Re: [twsocket] TWSocket and Client number

2011-01-18 Thread Angus Robertson - Magenta Systems Ltd
 What do I need to do to get the client number into the server?

You don't because the client number changes each time a new connection is
added or closed.  You have to lookup the number each time you need it.
Or design your application so it's not needed.  

Look at the FTP server component and it's demo project, which does
exactly what you are laboriously attempting to replicate.  It sends data
back to clients, in response to data sent by the clients. And it sends
files. 

Angus

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread daniel cc

Thanks Angus,
I don't know if we are at the same track,
The reason of trying to get the number of the client is: To use it for 
sending commands to the client as following,

SslWSocketServer1.Client[0].SendStr(ledSendCommand.Text + #13 + #10);

The idea is not the answer when the client asks something, it is to send 
command with out asking.

Let's say, I just want to send Reboot comand to the client.

If I have many clients connected and I have all the clients are listed in a 
TLISTBOX or in COMBOBOX and I just want to select one of them and send 
the command.


Thanks


-Original Message- 
From: Angus Robertson - Magenta Systems Ltd

Sent: Tuesday, January 18, 2011 11:48 AM
To: twsocket@elists.org
Subject: Re: [twsocket] TWSocket and Client number


What do I need to do to get the client number into the server?


You don't because the client number changes each time a new connection is
added or closed.  You have to lookup the number each time you need it.
Or design your application so it's not needed.

Look at the FTP server component and it's demo project, which does
exactly what you are laboriously attempting to replicate.  It sends data
back to clients, in response to data sent by the clients. And it sends
files.

Angus

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be 


--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread Angus Robertson - Magenta Systems Ltd
 If I have many clients connected and I have all the clients are 
 listed in a TLISTBOX or in COMBOBOX and I just want to select 
 one of them and send the command.

So you build your combobox, wait 10 seconds, one client disconnects, all
the clients numbers reduce by one and your combobox is out of date. When
you try to send a command to one of them it may be the wrong client or
you'll get an exception because there are fewer clients. 

That's why you were told to use PeerAddr and PeerPort of the client, not
a client number, and look it up immediately before sending a command.  

Or more sensibly, look at the protocol I outlined in the my first message
a few days ago, which included the computer name in the packet fields,
then you can store that and use that instead (assuming your computers
have sensible names.  You should be testing all this between multiple PCs
or VMs, as in real life, not 127.0.0.0 on a single PC. 

Angus

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread daniel cc

Thanks Angus,

So you build your combobox, wait 10 seconds, one client disconnects, all
the clients numbers reduce by one and your combobox is out of date. When
you try to send a command to one of them it may be the wrong client or
you'll get an exception because there are fewer clients.



I didn't think of this :(


That's why you were told to use PeerAddr and PeerPort of the client, not
a client number, and look it up immediately before sending a command.


This I have been working on but I just can't success, that is why I have 
been looking for an easier way.


Or more sensibly, look at the protocol I outlined in the my first message
a few days ago, which included the computer name in the packet fields,
then you can store that and use that instead (assuming your computers
have sensible names.  You should be testing all this between multiple PCs
or VMs, as in real life, not 127.0.0.0 on a single PC.



Yes,
I am already testing in real life and even the clients are behind of another 
network (not the same network).
I can't find the message you have sent with the computername in the packet 
fields.



--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread Angus Robertson - Magenta Systems Ltd
 I can't find the message you have sent with the computername in the 
 packet fields.

Last Thursday morning. 

My packets looked like this:

TxData: CV121RML-0002|NN130120080707-170202|20080707-170204||
RxData: CS010PC08|20080707-160204|0|RML-0002|

where CV was a client ident, CS server ident, three digits for the packet
type, then the computer name (RML-0002 or PC08) followed by | and a
variable number of extra fields depending on packet type.  

The document that described the protocol was over 50 pages long, with
about 70 different packets. The server echoed the client name at the end,
so the client knew it was getting the correct reply.  The database
document that controlled all this was 100 more pages. 

Angus

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread daniel cc

My packets looked like this:

TxData: CV121RML-0002|NN130120080707-170202|20080707-170204||
RxData: CS010PC08|20080707-160204|0|RML-0002|



Thanks Angus,
I understand what you mean but this unfortunately is too much for me :(
I can't make/handle this because I don't even know how to handle these 
TxData or RxData.


That is why I have been desperately seeking for an easier solution for 
sending commands to the client.


I have been trying to use the IP (PEERADDR) and the port (PEERPORT) in this,
SslWSocketServer1.Client[0].SendStr(ledSendCommand.Text + #13 + #10);
for trying to send with no success.

The command is gonna be typed into a TLabelEdit component which is text 
and sending requires integer and I still can't find the way of handling it.


such as: SslWSocketServer1.Client[PeerAddr ].SendStr(ledSendCommand.Text + 
#13 + #10); -- have tryed this in hundreds of ways and can't unfortunately 
make it work.


Do you think it would work if,
I create another TLabelEdit which will carrie the IP address of the client 
and convert it to an integer before use,


Use as,
Type the IP of the client into this TLabelEdit, convert it to integer.
Find the PeerAddr. which is placed in this label from the display component,

and than use as:
PeerAddr. := ledEdit.Text;  //this will be converted to integer
SslWSocketServer1.Client[ledIPEdit.Text].SendStr(ledSendCommand.Text + #13 + 
#10);


So far I haven't got any other ideas.


--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread RTT

On 18-01-2011 11:25, daniel cc wrote:



So you build your combobox, wait 10 seconds, one client disconnects, all
the clients numbers reduce by one and your combobox is out of date. When
you try to send a command to one of them it may be the wrong client or
you'll get an exception because there are fewer clients.



I didn't think of this :(


That's why you need a server socket listening at each client computer.
Every time the a client computer starts, connect to the Server computer 
and introduce himself. Hey, my name is Earl and I'm listening  to your 
commands at this Address. I will report to you any errors occurring here.
With this introduction message you can now add one more Client computer 
to your Combobox of the Server Application.  Now you have a Client 
that, even if disconnected, you know is listening at that Address for 
any command the Server wish to send.

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread daniel cc


That's why you need a server socket listening at each client computer.
Every time the a client computer starts, connect to the Server computer
and introduce himself. Hey, my name is Earl and I'm listening  to your
commands at this Address. I will report to you any errors occurring here.
With this introduction message you can now add one more Client computer
to your Combobox of the Server Application.  Now you have a Client
that, even if disconnected, you know is listening at that Address for
any command the Server wish to send.



There is a reason for not doing it.
The clients will be placed in different locations and the idea is to have 
ports opened only at the Server site.
Clients are not having static IP and the place where clients are gonna be 
doesn't allow top open any ports for incoming trafic etc.


Connecting from the server to the server placed in clients isn't going to 
work in my case or perhaps I am mistaking?


--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread Angus Robertson - Magenta Systems Ltd
 I have been trying to use the IP (PEERADDR) and the port (PEERPORT) 
 in this,
 SslWSocketServer1.Client[0].SendStr(ledSendCommand.Text + #13 + 
 #10); for trying to send with no success.
 The command is gonna be typed into a TLabelEdit component which 
 is text and sending requires integer and I still can't find the way 
 of handling it.

Sorry, but you really are out of your depth here, you need to understand
simple programming first.  We can not write your programme for you. 
 
However, you have to find the client number that matches the IP address
and port, by using a loop.  

clientnr := -1 ; 
for I := 0 to SslWSocketServer1.ClientCount do
begin 
if SslWSocketServer1.Client[I].GetPeerAddr = MyPeerAddr and 
SslWSocketServer1.Client[I].GetPeerPort = MyPeerPort then 
begin
clientnr := I;  // found it 
break; 
end;
end;
if clientnr = 0 then SslWSocketServer1.Client[clientnr].SendStr (etc)

MyPeerAddr and Port come from a table you saved earlier when each
connection was started.  The code above is not very efficient, there is
an overhead to GetPeerPort, so you should really save them as a derived
ClientClass, exactly as the FTP server does, look at the code.

Angus





--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread RTT

On 18-01-2011 13:50, daniel cc wrote:
Clients are not having static IP and the place where clients are gonna 
be doesn't allow top open any ports for incoming trafic etc.


Connecting from the server to the server placed in clients isn't going 
to work in my case or perhaps I am mistaking? 


If the Server needs to start a conversation, even if Client don't ask 
for nothing, then this is the only way to do it, because connections are 
not persistent. The other way is to have the Clients pooling the Server 
to ask if it needs to say something, if connection goes off :-)

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread daniel cc

Hi Angus,
I am very much pleased and I thank you very much for trying to help me out.


Sorry, but you really are out of your depth here, you need to understand
simple programming first.  We can not write your programme for you.



Yes,
I do have limited knowledge for now but, I am learning all the time.
The idea is not to make any application right now it is to just make the 
demo work in order to be able to test the components.
If I can make this demo first than I will have plenty of time for studying 
the rest of it :)


Communication between my app and the server is a very tiny part of it which 
is not going to be  very complicated either.
I am working on my app now and I will at the same time test the components 
before making the implementation.


I have made mistake twice regarding the ICS, I had chance to use them twice 
somewhile ago and I have skipped (because I didn't have time to study).

I am not going to skip now because I see too much good in ICS.

However, you have to find the client number that matches the IP address
and port, by using a loop.

clientnr := -1 ;
for I := 0 to SslWSocketServer1.ClientCount do
begin
   if SslWSocketServer1.Client[I].GetPeerAddr = MyPeerAddr and
   SslWSocketServer1.Client[I].GetPeerPort = MyPeerPort then
   begin
   clientnr := I;  // found it
   break;
   end;
end;
if clientnr = 0 then SslWSocketServer1.Client[clientnr].SendStr (etc)



About this piece of code,
What is the MyPeerAddr? -- Integer?

MyPeerAddr and Port come from a table you saved earlier when each
connection was started.  The code above is not very efficient, there is
an overhead to GetPeerPort, so you should really save them as a derived
ClientClass, exactly as the FTP server does, look at the code.

If you mean a database table,
I do not have any and I couldn't make this code work in any possible ways.

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread Angus Robertson - Magenta Systems Ltd
 What is the MyPeerAddr? -- Integer?

You can work that out yourself, look at what type GetPeerAddr returns. 

 If you mean a database table,

Not necessarily, it can a table in memory, made up of records, which you
use to keep track of all clients from which you update your GUI and keep
track of what you told the clients to do.  You probably only want to send
a reboot PC command once... 

It is actually faster to use FClientNo as per Marc's suggestion, since
this avoids stale sessions, the FTP server uses something similar. 

Angus

--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be


Re: [twsocket] TWSocket and Client number

2011-01-18 Thread daniel cc

Hi Angus,

You probably only want to send
a reboot PC command once...



Yes,
commands (just few) will be sent real seldom (once or twice in a week).
Communication will be made mostly by the client ans server will respond by 
doing very small things.


It is actually faster to use FClientNo as per Marc's suggestion, since
this avoids stale sessions, the FTP server uses something similar.



Yes,
Marc's solution looks excellent, it is easy to find by searching the memo 
component directly from the code and very easy to copy to XML file for 
creating client list etc.


I would like to thank you once more for all the help and specially for being 
pation.


With best regards 


--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://lists.elists.org/cgi-bin/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be