[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


[twsocket] ANN: Magenta Systems Mail Queue Component

2011-01-18 Thread Angus Robertson - Magenta Systems Ltd

Free download from: http://www.magsys.co.uk/delphi/magics.asp

This new ICS component has been used in our ComCap application to send
emails for the last three months.  

Magenta Systems Mail Queue Component has two main benefits over a simple
TSslSmtpCli component: it supports extended retries over many hours or
days, and supports multiple SMTP relay servers, while alleviating the
need for the application to handle retries.  The component also allows
HTML mail to be sent using SSL, something THtmlSmtpCli does not currently
support. Mail is queued to disk, so retries will continue if the
application is restarted.  

TMagMailQueue is designed to prepare, queue and send email. Preparing the
email is done using the ICS THtmlSmtpCli component so it may be plain
text or HTML email with one or more file attachments.

Once the mail properties in QuHtmlSmtp have been specified, it is queued
using the QueueMail method which saves it to an EML spool file.

The component runs a thread which checks the queue for new EML spool
files, and attempts to forward them to one or more SMTP Mail Servers
using TSslSmtpCli, optionally with SSL. If mail delivery succeeds, the
spool file may be deleted or moved to an archive folder. If mail delivery
fails, the spool file remains in the queue and further attempts are made
separated by the times in minutes listed in the RetryList list. If all
delivery attempts fail, the spool file may be deleted or moved to a
badmail folder.

Note that some email servers support grey listing and reject the first
email attempt from a new sender but allow a retry 10 or 15 minutes later,
something that is very effective in blocking spam emails (since they
don't usually retry).

If multiple mail servers are specified, delivery is attempted once using
each server, for each retry attempt. Each mail server is specified as
TMailServer and there is no limit to the total.

Each time the queue is updated or a delivery attempt made, the queue is
saved to file in the control folder, so the component may be stopped and
restarted with failed attempts continuing.

The EML spool files are compatible with those created by many Microsoft
email applications such as CDO, and the AddtoQueue method can also be
used to queue existing EML files with the queue details specified in
MailQuItem.

Note, this component is intended for sending low volume email from
individual Delphi applications, with more flexibility than a simple
TSslSmtpCli component. For use as a heavy duty SMTP server, queue
processing could be improved to avoid moving records around as much or
saving them to disk as often, and mail bodies could be read as required
from disk instead of being read entirely to memory first. DNS look-up
could be added to find the MX records for each domain to send email
directly. A mail pickup folder could be added which is scanned for new
EML files. Finally, an SMTP server component could be added to accept new
email on port 25, and save it as EML files for redelivery. Beware such an
addition has various security implications for open relaying and spam
detection.

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,
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] SslWSocketServer SslWSocket

2011-01-18 Thread daniel cc

Hi Marc,
Your code works perfectly :)
It created the UniqueID for the client and I believe this just was what I 
needed. Now I will be able to select the client of my choice with this ID.

I will do the rest and start testing.

Thanks a lot for the great help :)

Best regards

-Original Message- 
From: Marc Charbonneau

Sent: Tuesday, January 18, 2011 3:58 PM
To: ICS support mailing
Subject: Re: [twsocket] SslWSocketServer  SslWSocket


Thanks Marc,
Have been playing 2 days with this and still can't find out the way how 
to

do.


Ok, here's a simple solution with TcpSrv demo :

In TTcpSrvForm declaration, in the private part, add this

   FClientNo : integer;

Now, go in procedure TTcpSrvForm.WSocketServer1ClientConnect and
change the code to look like this :
procedure TTcpSrvForm.WSocketServer1ClientConnect(
   Sender : TObject;
   Client : TWSocketClient;
   Error  : Word);
begin
   with Client as TTcpSrvClient do begin
   Inc(FClientNo); // Increment unique client no
   Tag := FClientNo; // tag connecting client with it's id
   Display('Client connected. UniqueID : ' + IntToStr(Tag) +
   ' 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;
   ConnectTime := Now;
   end;
end;

Now, change your SendCommand procedure to something like this :

procedure TTcpSrvForm.SendCommand(ClientNo: integer; CommandText: string);
var
 i: integer;
begin
for i := 0 to WSocketServer1.ClientCount -1 do
begin
 // iterate all client trying to find the right one
  if WSocketServer1.Client[i].Tag = ClientNo then
  begin
WSocketServer1.Client[i].SendStr(CommandText);
Display('Command sent: ' + CommandText);
   break;
  end;
end;
end;

This should do what you want.

hope this help

Marc
--
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] ANN: Magenta Systems Mail Queue Component

2011-01-18 Thread Arno Garrels
Angus Robertson - Magenta Systems Ltd wrote:
 Free download from: http://www.magsys.co.uk/delphi/magics.asp

Sounds very interesting, thanks for giving it to the community.

-- 
Arno Garrels

--
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


[twsocket] SslWSocket processing data

2011-01-18 Thread daniel cc
Hi guys,
If the SslWSocket sends command such as: “Time”,
SslWSocketServer is processing it and responding by giving the time to the 
client (this what I have noticed in the samples).

Now,
Can the same thing be done in the other way around?
SslWSocketServer sends command such as : ”Time”,
SslWSocket answers by sending the current time to the SslWSocketServer after 
processing.

I know how to do this in some other ways but wondering if it is possible to do 
it with the component since it is doing it in much better way.

My question will be,
can this be done for the client side where the client receives command from the 
server, processes it and responds to the server.
---
procedure TSimpleSslServerForm.ProcessData(Client: TTcpSrvClient);
var
I   : Integer;
P   : Pointer;
AClient : TTcpSrvClient;
begin
{ We could replace all those CompareText with a table lookup }
---

Thanks
--
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