Re: [twsocket] SslWSocketServer SslWSocket
-Original Message- From: Francois PIETTE Sent: Monday, January 17, 2011 9:33 AM To: ICS support mailing Subject: Re: [twsocket] SslWSocketServer SslWSocket and it doesn't work Please be more specific. What error/exception do you have ? Hi Francois, Thanks for the response and being pation. I have checked in the project the -- OnDataAvailable as you adviced and it is absolutely same as what I also have. What I am trying to do is, Server is on and running, client is connected and I have the info on Display which says about what client is connected etc. Now, How can I selected a specific client, let's say client 1 and send a command to it? Here is what I am trying, SslWSocketServer1.(Sender).Send(MyBufAddr, MyBufLnegth); -- need to be able to send the command which is typed in the TEdit field and I have no idea about how this works, so far I don't even know how to handle -- (MyBufAddr, MyBufLnegth); either. After sending the command to the client, Display('Command sent: ' + ledSendCommand.Text); -- ledSendCommand is a TLabelEdit -daniel -- 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
and it doesn't work Please be more specific. What error/exception do you have ? You have not answered this one. How can I selected a specific client, let's say client 1 and send a command to it? Speaking about code, you select it by its index in the Client[] property. How you find the right index is YOUR application problem. Tell me in english how you would like to select one client among all the connected clients and I will help you translate this specification to code. But, are you sure you don't want to revert the client/server roles ? It would be much simpler for you. If the side you name server has to send commands to the side you name client for execution and get back results, then what you name server is actually a socket client and what you name client is actually a socket server. To say it otherwise: There is no problem having the computer you name server to be an actual client - as far as socket programming is concerned - for the computer you name as client which is turn would be a server as far as socket programming is concerned. You may also have both client and server socket at both side. By the way, this is how FTP is working: the FTP client connect to the FTP server to send commands (file transfert, dir list,...) to be executed by the server. When the FTP server has to transfert a file, the (FTP) server become a (socket) client connecting to a (server) socket located at the (FTP) client ! This could be a scheme you could use to design your application. SslWSocketServer1.(Sender).Send(MyBufAddr, MyBufLnegth); -- need to be able to send the command which is typed in the TEdit field and I have no idea about how this works, so far I don't even know how to handle -- (MyBufAddr, MyBufLnegth); either. Excuse me, don't take it worng, but I'm wondering if you know Delphi programming or not :-( You can see in the component source code and in the samples that Send method takes two arguments, the first is a pointer to what you want to send and the second is the number of bytes to send. You have a lot of ways to use that in your software ! If you only have text to send, probably SendStr() method will be easier for you: it take a single string type argument. Look at the implementation to learn how SendStr() call Send()... -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be - Original Message - From: daniel cc dan...@signedsource.com To: ICS support mailing twsocket@elists.org Sent: Monday, January 17, 2011 9:15 AM Subject: Re: [twsocket] SslWSocketServer SslWSocket -Original Message- From: Francois PIETTE Sent: Monday, January 17, 2011 9:33 AM To: ICS support mailing Subject: Re: [twsocket] SslWSocketServer SslWSocket and it doesn't work Please be more specific. What error/exception do you have ? Hi Francois, Thanks for the response and being pation. I have checked in the project the -- OnDataAvailable as you adviced and it is absolutely same as what I also have. What I am trying to do is, Server is on and running, client is connected and I have the info on Display which says about what client is connected etc. Now, How can I selected a specific client, let's say client 1 and send a command to it? Here is what I am trying, SslWSocketServer1.(Sender).Send(MyBufAddr, MyBufLnegth); -- need to be able to send the command which is typed in the TEdit field and I have no idea about how this works, so far I don't even know how to handle -- (MyBufAddr, MyBufLnegth); either. After sending the command to the client, Display('Command sent: ' + ledSendCommand.Text); -- ledSendCommand is a TLabelEdit -daniel -- 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] SslWSocketServer SslWSocket
and it doesn't work Please be more specific. What error/exception do you have ? You have not answered this one. Most of the errors were -- Socket not connected. Speaking about code, you select it by its index in the Client[] property. How you find the right index is YOUR application problem. Tell me in english how you would like to select one client among all the connected clients and I will help you translate this specification to code. Here is what need to do, When the client is connected, It informs it's IP and connection port to the server as this: Client connected. Remote: 127.0.0.1/51665 Local: 127.0.0.1/443 I need to be able to use this information or ar least some of this information to send some commands this client. But, are you sure you don't want to revert the client/server roles ? It would be much simpler for you. I am sorry but I don't understand what you mean with this, Windows server/client rules or component? If the side you name server has to send commands to the side you name client for execution and get back results, then what you name server is actually a socket client and what you name client is actually a socket server. To say it otherwise: There is no problem having the computer you name server to be an actual client - as far as socket programming is concerned - for the computer you name as client which is turn would be a server as far as socket programming is concerned. You may also have both client and server socket at both side. By the way, this is how FTP is working: the FTP client connect to the FTP server to send commands (file transfert, dir list,...) to be executed by the server. When the FTP server has to transfert a file, the (FTP) server become a (socket) client connecting to a (server) socket located at the (FTP) client ! This could be a scheme you could use to design your application. Do you think I need both in both sides? If yes, Is it going to make any easier for me? I need to start with sending commands but I need to send and receive files also in feature. SslWSocketServer1.(Sender).Send(MyBufAddr, MyBufLnegth); -- need to be able to send the command which is typed in the TEdit field and I have no idea about how this works, so far I don't even know how to handle -- (MyBufAddr, MyBufLnegth); either. Excuse me, don't take it worng, but I'm wondering if you know Delphi programming or not :-( You can see in the component source code and in the samples that Send method takes two arguments, the first is a pointer to what you want to send and the second is the number of bytes to send. You have a lot of ways to use that in your software ! If you only have text to send, probably SendStr() method will be easier for you: it take a single string type argument. Look at the implementation to learn how SendStr() call Send()... Sorry again for not being able to explain clearly, There is, .Send .SendSTR .SendLine My problem is, What is the right way and how can I get the result I need? 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
Re: [twsocket] SslWSocketServer SslWSocket
But, are you sure you don't want to revert the client/server roles ? It would be much simpler for you. I am sorry but I don't understand what you mean with this, Windows server/client rules or component? Do you think I need both in both sides? Here is how I see your problem solved: First let agree on terminology. I need 4 names: master, remote, client and server. I will name remote computer or simply remote the group of computers you currently name client. I will name master computer or simply master the computer you actually name server. I will name server socket or simply server a socket which passively wait (listen) for incomming connections. I will name client socket or simply client a socket which will do whatever is needed to establish a connection. Here are a few consequences: Client socket will connect to server socket. A socket server may have a lot of client connected. Remote computer can have either or both client and server socket. Master computer can have either or both client and server socket. Here is how the whole application, distributed between remote (several) and master (only one) comoputer would operate. The master computer shall have a single server socket waiting (listening) for remote computer connections. A remote computer (there are a lot of them) shall connect to the master computer using a client socket. A remote computer shall send commands to the master. Basically there are two commands: subscribe and unsubscribe. Master computer receiving the subscribe command will add the remote computer in a list of remote computers participating in the work. Wehn receiving the unsubscribe command, the master computer will remove a remote computer from the list. The master computer, having the list of all participating remote computers will be able to send commands to each remote computer. To do so, the master computer shall use a client socket to connect to the server socket listening at remote computer side. Obviously, each remote computer has a server socket waiting for connections and commands from the master they subscribed. That socket is programmed to accept only connections from the master after subscriuption take place. Remote computer receiving commands from master computer will execute the command and return result back to the master computer. This is a general picture of your software as I see it. Many details remains to be fixed but you get the general ideas. Other solutions are obviously possible, including using server socket only at master side. I can develop a specific set of demo programs for you, but not for free. Contact me by email if you want an offer. Regards, -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be - Original Message - From: daniel cc dan...@signedsource.com To: ICS support mailing twsocket@elists.org Sent: Monday, January 17, 2011 11:03 AM Subject: Re: [twsocket] SslWSocketServer SslWSocket and it doesn't work Please be more specific. What error/exception do you have ? You have not answered this one. Most of the errors were -- Socket not connected. Speaking about code, you select it by its index in the Client[] property. How you find the right index is YOUR application problem. Tell me in english how you would like to select one client among all the connected clients and I will help you translate this specification to code. Here is what need to do, When the client is connected, It informs it's IP and connection port to the server as this: Client connected. Remote: 127.0.0.1/51665 Local: 127.0.0.1/443 I need to be able to use this information or ar least some of this information to send some commands this client. But, are you sure you don't want to revert the client/server roles ? It would be much simpler for you. I am sorry but I don't understand what you mean with this, Windows server/client rules or component? If the side you name server has to send commands to the side you name client for execution and get back results, then what you name server is actually a socket client and what you name client is actually a socket server. To say it otherwise: There is no problem having the computer you name server to be an actual client - as far as socket programming is concerned - for the computer you name as client which is turn would be a server as far as socket programming is concerned. You may also have both client and server socket at both side. By the way, this is how FTP is working: the FTP client connect to the FTP server to send commands (file transfert, dir list,...) to be executed by the server. When the FTP server has to transfert a file, the (FTP) server become a (socket) client connecting to a (server) socket located at the (FTP) client ! This could be a scheme you could use to design your application. Do you think I need both in both sides? If yes,
Re: [twsocket] SslWSocketServer SslWSocket
Other solutions are obviously possible, including using server socket only at master side. My application only used a server at the master side, albeit three for redundnacy, so the clients only contacted the servers to report status and pick-up waiting commands. Actually, this was partially true, there was an emergency server in the client PCs in case something went wrong. But there were also UDP broadcasts from the servers every 30 seconds, if they wanted the clients to call home more urgently. These packets also served to confirm that networking was all OK for the clients. Some of this depends on the session duration strategy, whether clients contact the servers say once a minute or every five minutes or something, or if they leave the connection open continually. Short sessions are better for resources, fewer connections, but is horrible for SSL due to the massive overhead establishing a session and checking certificates. This is probably why Arno suggested not using SSL but just data packet encryption. Permanent sessions solve the connection overhead and allow easy commands from the server, but may cause resource problems on the servers, routers and firewalls, and there are stale session issues if the client disappears unexpectedly such as with wireless LANs where you need timeouts and keep alive packets. As we have all said repeatedly, SSL is a minor issue compared to other design concepts and should be left until a lot of other issues are resolved. Also, sending file using a private protocol is simply re-inventing FTP and will add substantially to project cost and timetable. It may be OK for the odd short file, but anything more complicated should use FTP. My project was the reason I spent a lot of time in the few years improving FTP and adding many new FTP commands. 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] SslWSocketServer SslWSocket
Guys, Looks like nothing is possible to do in the simple and basic ways with ICS?? I was just thinking that I have understood a bit of the components today and now you guys are making it lot more complicated for me. All I need is, A server who accepts the clients and tells me which clients are online, can send once a while a simple command such as: reboot or send a file such as: setup.exe A client who accepts the command: reboot from the server and does the asked, receives the file setup.exe and does the asked. The server will have maximum of 200 clients nothing more. Sounds simple? I can do this in 2 hours with TCUSTOMSOCKET of Delphi and protect it with SSH tunnel. Why don't I? Simple: because I want to do it with SSL in order to be able to have the better security, to have it in whole one piece and that is also the reason why I am not interested of doing it with the regular components because I can't secure them, because I don't have the knowledge of securing them. Now, Could you please answer, can this be done with ICS or not? if yes, can you help me with the following procedure? - {This procedure sends the command to the clients and it works very nicely.} procedure TSimpleSslServerForm.SendCommand; begin SslWSocketServer1.Client[0].SendStr(ledSendCommand.Text); /// The PROBLEM here is: How do I send the command to a specific client if I have more than one client? Display('Command sent: ' + ledSendCommand.Text); end; -- Thanks in advance -daniel -Original Message- From: Francois PIETTE Sent: Monday, January 17, 2011 3:55 PM To: ICS support mailing Subject: Re: [twsocket] SslWSocketServer SslWSocket But, are you sure you don't want to revert the client/server roles ? It would be much simpler for you. I am sorry but I don't understand what you mean with this, Windows server/client rules or component? Do you think I need both in both sides? Here is how I see your problem solved: First let agree on terminology. I need 4 names: master, remote, client and server. I will name remote computer or simply remote the group of computers you currently name client. I will name master computer or simply master the computer you actually name server. I will name server socket or simply server a socket which passively wait (listen) for incomming connections. I will name client socket or simply client a socket which will do whatever is needed to establish a connection. Here are a few consequences: Client socket will connect to server socket. A socket server may have a lot of client connected. Remote computer can have either or both client and server socket. Master computer can have either or both client and server socket. Here is how the whole application, distributed between remote (several) and master (only one) comoputer would operate. The master computer shall have a single server socket waiting (listening) for remote computer connections. A remote computer (there are a lot of them) shall connect to the master computer using a client socket. A remote computer shall send commands to the master. Basically there are two commands: subscribe and unsubscribe. Master computer receiving the subscribe command will add the remote computer in a list of remote computers participating in the work. Wehn receiving the unsubscribe command, the master computer will remove a remote computer from the list. The master computer, having the list of all participating remote computers will be able to send commands to each remote computer. To do so, the master computer shall use a client socket to connect to the server socket listening at remote computer side. Obviously, each remote computer has a server socket waiting for connections and commands from the master they subscribed. That socket is programmed to accept only connections from the master after subscriuption take place. Remote computer receiving commands from master computer will execute the command and return result back to the master computer. This is a general picture of your software as I see it. Many details remains to be fixed but you get the general ideas. Other solutions are obviously possible, including using server socket only at master side. I can develop a specific set of demo programs for you, but not for free. Contact me by email if you want an offer. Regards, -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) http://www.overbyte.be - Original Message - From: daniel cc dan...@signedsource.com To: ICS support mailing twsocket@elists.org Sent: Monday, January 17, 2011 11:03 AM Subject: Re: [twsocket] SslWSocketServer SslWSocket and it doesn't work Please be more specific. What error/exception do you have ?
Re: [twsocket] SslWSocketServer SslWSocket
A server who accepts the clients and tells me which clients are online, can send once a while a simple command such as: reboot or send a file such as: setup.exe A client who accepts the command: reboot from the server and does the asked, receives the file setup.exe and does the asked. The server will have maximum of 200 clients nothing more. Sounds simple? I can do this in 2 hours with TCUSTOMSOCKET of Delphi and protect it with SSH tunnel. Could you please answer, can this be done with ICS or not? If you think you can write and test the project in two hours with that Delphi component, just go and do it. A lot of people here are spending a lot of time trying to help you, for free, whether you wish to listen to our advice or not is your choice. All the code you need is in the samples, and protocols like FTP client and server, you just need to spend some time looking at the code and understanding it. I did it, numerous other people have done it, you can do it, but not in two hours. 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] SslWSocketServer SslWSocket
Looks like nothing is possible to do in the simple and basic ways with ICS?? Wrong impression. All I need is, A server who accepts the clients and tells me which clients are online, can send once a while a simple command such as: reboot or send a file such as: setup.exe A client who accepts the command: reboot from the server and does the asked, receives the file setup.exe and does the asked. The server will have maximum of 200 clients nothing more. Have a look at TnSrv sample. It open a new form for each client and you are trhen able to use that form to send text to the client. TnSrv is closer to what you want to do but IMO do not represent the best way to program with ICS. Could you please answer, can this be done with ICS or not? Yes it can. if yes, can you help me with the following procedure? {This procedure sends the command to the clients and it works very nicely.} procedure TSimpleSslServerForm.SendCommand; begin SslWSocketServer1.Client[0].SendStr(ledSendCommand.Text); /// The PROBLEM here is: How do I send the command to a specific client if I have more than one client? Display('Command sent: ' + ledSendCommand.Text); end; You can iterate thru Client[] array to find a client with the properties you need. You have direct access to IP and Port (look properties with peer in their name). And you can add any properties you like by deriving a new class and assigning it to TWSocketServer.ClientClass. -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) 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] SslWSocketServer SslWSocket
Angus, Thanks for the response, I am very pleased with all the help I have got here and I do love ICS components. I wouldn't be trying do do anything with them would I? If I wouldn't be happy with the components and with the help. What I need here is some easy basic things not complecated ones. I have been studying the components for about a week now and I already can do many things with them. So, My questions still remains, can I do what I need with ICS? Yes I can do with Delphi's TCUSTOMSOCKET because I already have an appliccation which does many things in my LAN environment (it is server and client based as well). But, I don't think it is as good as ICS and that is the reason why I would like to be able to understand and do things with ICS. All I am trying to do with ICS right now is a simple demo for testing and to see how things are going to work and I believe that shouldn't take more than a week to achive. I have been checking all the demos and trying to understand about how to send a Command to a specific client and I simply can't find it! There are too many projects where the things are handled differently in each of them and none sends commands to the server. I have made this test procedure which works but only if there is just one client. - {This procedure sends the command to the clients and it works very nicely.} procedure TSimpleSslServerForm.SendCommand; begin SslWSocketServer1.Client[0].SendStr(ledSendCommand.Text); /// The PROBLEM here is: How do I send the command to a specific client if I have more than one client? Display('Command sent: ' + ledSendCommand.Text); end; - A server who accepts the clients and tells me which clients are online, can send once a while a simple command such as: reboot or send a file such as: setup.exe A client who accepts the command: reboot from the server and does the asked, receives the file setup.exe and does the asked. The server will have maximum of 200 clients nothing more. Sounds simple? I can do this in 2 hours with TCUSTOMSOCKET of Delphi and protect it with SSH tunnel. Could you please answer, can this be done with ICS or not? If you think you can write and test the project in two hours with that Delphi component, just go and do it. A lot of people here are spending a lot of time trying to help you, for free, whether you wish to listen to our advice or not is your choice. All the code you need is in the samples, and protocols like FTP client and server, you just need to spend some time looking at the code and understanding it. I did it, numerous other people have done it, you can do it, but not in two hours. 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] SslWSocketServer SslWSocket
I have been checking all the demos and trying to understand about how to send a Command to a specific client and I simply can't find it! You found it because you told us: I have made this test procedure which works but only if there is just one client. {This procedure sends the command to the clients and it works very nicely.} procedure TSimpleSslServerForm.SendCommand; begin SslWSocketServer1.Client[0].SendStr(ledSendCommand.Text); /// The PROBLEM here is: How do I send the command to a specific client if I have more than one client? Display('Command sent: ' + ledSendCommand.Text); end; Your problem is not how to send to a given client, you've done that with the first client (index is 0) and it is the same for any other client, just change the index. Your problem is at the application level: How do I select the right client ? Said in other word: How do I find the index to use with Client[] property ? We cannot answer that question for you because we don't know the criteria ! You can create a form to ask the user which IP the client has and then iterate thru Client[] array and look for the correct IP. Or you can show the list of clients on screen (again by iterating thru Client[] array) and let the user select the one he wants. Do you understand what I mean ? -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) 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] SslWSocketServer SslWSocket
I have made this test procedure which works but only if there is just one client. - {This procedure sends the command to the clients and it works very nicely.} procedure TSimpleSslServerForm.SendCommand; begin SslWSocketServer1.Client[0].SendStr(ledSendCommand.Text); /// The PROBLEM here is: How do I send the command to a specific client if I have more than one client? Display('Command sent: ' + ledSendCommand.Text); end; - SslWSocketServer1.Client is an array of your clients. So if you have 2 clients, the first one is Client[0] and the second one is Client[1]. If you have a third client then he's at Client[2]. I think you get the picture so change your procedure to something like this : procedure TSimpleSslServerForm.SendCommand(ClientNo: integer); begin SslWSocketServer1.Client[ClientNo].SendStr(ledSendCommand.Text); Display('Command sent: ' + ledSendCommand.Text); end; The number of connected client is available in TWSocketServer.ClientCount hth -- 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
Said in other word: How do I find the index to use with Client[] property ? We cannot answer that question for you because we don't know the criteria ! You can create a form to ask the user which IP the client has and then iterate thru Client[] array and look for the correct IP. Yes, This is what I need and Iam trying to send command to the client by using it's IP As I can see here (OnProcessData) that I am getting the IP -- Client.SendStr(AClient.PeerAddr + ':' + AClient.GetPeerPort + ' ' + but, I don't know how to do this, and that is what I have been looking in the demos to find today. Yes, I do understand :) -- 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
- SslWSocketServer1.Client is an array of your clients. So if you have 2 clients, the first one is Client[0] and the second one is Client[1]. If you have a third client then he's at Client[2]. I think you get the picture Yes, I get the picture. so change your procedure to something like this : procedure TSimpleSslServerForm.SendCommand(ClientNo: integer); begin SslWSocketServer1.Client[ClientNo].SendStr(ledSendCommand.Text); Display('Command sent: ' + ledSendCommand.Text); end; How do you set this -- (ClientNo)? How do you get the number in here? Can you please explain a bit? -- 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
daniel cc wrote: - SslWSocketServer1.Client is an array of your clients. So if you have 2 clients, the first one is Client[0] and the second one is Client[1]. If you have a third client then he's at Client[2]. I think you get the picture Yes, I get the picture. so change your procedure to something like this : procedure TSimpleSslServerForm.SendCommand(ClientNo: integer); begin SslWSocketServer1.Client[ClientNo].SendStr(ledSendCommand.Text); Display('Command sent: ' + ledSendCommand.Text); end; How do you set this -- (ClientNo)? How do you get the number in here? Can you please explain a bit? What is so difficult? Property Client is an array of currently connected client objects, property ClientCount returns the number of objects in that array. You work with it like with a standard Delphi TList as well. For example, in order to iterate over all client objects: var Cli: TWSocketClient; begin for i := 0 to WSocketServer1.ClientCount -1 do begin Cli := WSocketServer1.Client[i]; if Cli meets some condition here then Call some Cli.method; end; end; However usually a protocol follows the request/response pattern. That is client requests something and server responds to that client request, usually there's no need to iterate over the client list or to search for a particular client object. -- 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] SslWSocketServer SslWSocket
so change your procedure to something like this : procedure TSimpleSslServerForm.SendCommand(ClientNo: integer); begin SslWSocketServer1.Client[ClientNo].SendStr(ledSendCommand.Text); Display('Command sent: ' + ledSendCommand.Text); end; How do you set this -- (ClientNo)? How do you get the number in here? Can you please explain a bit? Well, without knowing more on your setup, one way I can see to differentiate your clients is with their IP. The client IP is available in Client[x].PeerAddr. hth -- 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
What is so difficult? Property Client is an array of currently connected client objects, property ClientCount returns the number of objects in that array. You work with it like with a standard Delphi TList as well. For example, in order to iterate over all client objects: The difficulty is that I am quite lost with this and can't find a way of sending command to the client of my choice. var Cli: TWSocketClient; begin for i := 0 to WSocketServer1.ClientCount -1 do begin Cli := WSocketServer1.Client[i]; if Cli meets some condition here then Call some Cli.method; end; end; Where do I call this exactly? During the send? or receive? Or a spearate procedure? how? The problem here is, You guys are treating me like an expert and I just don't understand half of the things what you are saying. -- 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
Well, without knowing more on your setup, one way I can see to differentiate your clients is with their IP. The client IP is available in Client[x].PeerAddr. My setup? I am working on a demo, I have memo field where I need to see the number of the client. If I can get the number of the client than I will be able to do the rest. Could you please help me out to get the client number into that memo? I hope this help. -- 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
On Mon, Jan 17, 2011 at 2:26 PM, daniel cc dan...@signedsource.com wrote: Well, without knowing more on your setup, one way I can see to differentiate your clients is with their IP. The client IP is available in Client[x].PeerAddr. My setup? I am working on a demo, I have memo field where I need to see the number of the client. Which client ? Like I said, if you have only 1 client, his number will be 0. If you have more than 1 client, then client 2 will be number 1 since Delphi use 0-based array. How do you differentiate your clients ? The server socket will just add all connecting client to the Client array. You have to know which one is which. If you only want to send commands to all connected clients, just iterate over all your clients (like Arno told you) and send the command to each one. If I can get the number of the client than I will be able to do the rest. Could you please help me out to get the client number into that memo? That's what I and others are trying to do. BTW, I'm not currently using ICS for anything, but I've done a lot in the past. I'm an ICS user since around 1999 and I can tell you that it's rock-solid. I think you should study the TcpSrv demo, as I've learned a lot with it. hth -- 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
Said in other word: How do I find the index to use with Client[] property ? We cannot answer that question for you because we don't know the criteria ! You can create a form to ask the user which IP the client has and then iterate thru Client[] array and look for the correct IP. Yes, This is what I need and Iam trying to send command to the client by using it's IP As I can see here (OnProcessData) that I am getting the IP -- Client.SendStr(AClient.PeerAddr + ':' + AClient.GetPeerPort + ' ' + but, I don't know how to do this, and that is what I have been looking in the demos to find today. Something like this ? (Out of my head, not tested) for ClientNo := 0 to WSocketServer1.ClientCount - 1 do begin if Client[ClientNo].PeerAddr = '192.168.1.123' then begin Client[ClientNo].SendStr('HelloWorld'#13#10); break; end; end; -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) 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] SslWSocketServer SslWSocket
Something like this ? (Out of my head, not tested) for ClientNo := 0 to WSocketServer1.ClientCount - 1 do begin if Client[ClientNo].PeerAddr = '192.168.1.123' then begin Client[ClientNo].SendStr('HelloWorld'#13#10); break; end; end; Hi Francois, Could you please check the following code of both server and client procedures and tell me what is missing in order to be able to get the client number into the DISPLAY with the all other info.This is code writen by you i think. I have add few things and there might be mistakes. I am certain, I will be okay after that. Thanks a lot in advance. Here is procedures OnDataAvailable and ProcessData of the SERVER - {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} procedure TSimpleSslServerForm.ClientDataAvailable( Sender : TObject; Error : Word); begin with Sender as TTcpSrvClient do begin { We use line mode. We will receive complete lines } RcvdLine := ReceiveStr; { Remove trailing CR/LF } while (Length(RcvdLine) 0) and IsCharInSysCharSet(RcvdLine[Length(RcvdLine)], [#13, #10]) do RcvdLine := Copy(RcvdLine, 1, Length(RcvdLine) - 1); Display('Received from ' + GetPeerAddr + ': ''' + RcvdLine + ); ProcessData(Sender as TTcpSrvClient); end; end; {* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *} procedure TSimpleSslServerForm.ProcessData(Client: TTcpSrvClient); var I : Integer; P : Pointer; AClient : TTcpSrvClient; begin { We could replace all those CompareText with a table lookup } if CompareText(Client.RcvdLine, 'help') = 0 then Client.SendStr('Commands are:' + #13#10 + ' exit' + #13#10 + ' who' + #13#10 + ' time' + #13#10 + ' exception' + #13#10 + ' binary [size]' + #13#10) else if CompareText(Copy(Client.RcvdLine, 1, 6), 'binary') = 0 then begin I := StrToIntDef(Copy(Client.RcvdLine, 7, MaxInt), 0); if I = 0 then Client.SendStr('500 Error binary size not spezified'#13#10) else begin if I MaxWord then begin Client.SendStr('500 Error binary size limited to ' + IntToStr(MaxWord) + ' bytes'#13#10); Exit; end else Client.SendStr('200 OK Binary ' + IntToStr(I) + ' bytes requested'#13#10); Inc(I, SizeOf(THdrRec)); GetMem(P, I); try FillChar(P^, I, '1'); PHdrRec(P)^.ID := 0; // any value 32 marks = valid binary data. PHdrRec(P)^.Size:= I - SizeOf(THdrRec); PAnsiChar(P)[I - 1] := 'E'; Client.Send(P, I); finally FreeMem(P); end; end; end else if CompareText(Client.RcvdLine, 'exit') = 0 then { We can't call Client.Close here because we will immediately } { reenter DataAvailable event handler with same line because } { a line is removed from buffer AFTER it has been processed. } { Using CloseDelayed will delay Close until we are out of } { current event handler. } Client.CloseDelayed else if CompareText(Client.RcvdLine, 'time') = 0 then { Send server date and time to client } Client.SendStr(DateTimeToStr(Now) + #13#10) else if CompareText(Client.RcvdLine, 'who') = 0 then begin { Send client list to client } Client.SendStr('There are ' + IntToStr(SslWSocketServer1.ClientCount) + ' connected users:' + #13#10); for I := SslWSocketServer1.ClientCount - 1 downto 0 do begin AClient := TTcpSrvClient(SslWSocketServer1.Client[I]); Client.SendStr(AClient.PeerAddr + ':' + AClient.GetPeerPort + ' ' + DateTimeToStr(AClient.ConnectTime) + #13#10); end; end else if CompareText(Client.RcvdLine, 'exception') = 0 then { This will trigger a background exception for client } PostMessage(Client.Handle, Client.FMsg_WM_TRIGGER_EXCEPTION, 0, 0) else if Client.State = wsConnected then Client.SendStr('Unknown command: ''' + Client.RcvdLine + + #13#10); end; - And here is OnDataAvailable for the client. - procedure TfrmMain.SockDataAvailable(Sender: TObject; ErrCode: Word); var Buf : array [0..255] of AnsiChar; Len : Integer; begin Len :=
Re: [twsocket] SslWSocketServer SslWSocket
Have a look at the event OnClientConnect, this is called whenever a client connect, just grab the client info there and you should be good to go. Thank you :) Now we are getting close. Here is what I have, and please see the line for the client number, Now I at least now where should I define it, just need to find out how? --- procedure TSimpleSslServerForm.SslWSocketServer1ClientConnect( Sender : TObject; Client : TWSocketClient; Error : Word); begin with Client as TTcpSrvClient do begin Display('Client connected.' + '[]' + ///Here I need to get the client number into the brackets ' 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] SslWSocketServer SslWSocket
Could you please check the following code I normally don't review large chunk of code within free support. I usually do that when I have a consulting contract. Could you please check the following code of both server and client procedures and tell me what is missing in order to be able to get the client number into the DISPLAY with the all other info.This is code writen by you i think. I have add few things and there might be mistakes. I don't know what the client number is. If it is the index in the client[] property, then you are on the wrong track. That index vary as clients connects and disconnects ! The index may be used only in temporary operation will the list won't change, for example within the handling of an event. using the index on the long term is a bad idea. In my opinion, each of your client should be assigned an unique ID, either sent my the client himself, or generated by the server (Simple incrementing number). The ID is somewhat necessary because you may have several client from the same computer and hence have the same IP for several clients. You could also use IP:Port as an ID. As Marc told you, if you need to display a list of client, real time, you have to use the WSocketServer OnClientConnect and OnClientDisconnect events to add/:remove items to/from the list you use for display. in both events you have access to the client instalnce and can thus access PeerAddr, PeerPort and any other data you may have (One of the demo save the time of connection just for demo purpose). -- francois.pie...@overbyte.be The author of the freeware multi-tier middleware MidWare The author of the freeware Internet Component Suite (ICS) 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] SslWSocketServer SslWSocket
Here is what I have, and please see the line for the client number, Now I at least now where should I define it, just need to find out how? --- procedure TSimpleSslServerForm.SslWSocketServer1ClientConnect( Sender : TObject; Client : TWSocketClient; Error : Word); begin with Client as TTcpSrvClient do begin Display('Client connected.' + '[]' + ///Here I need to get the client number into the brackets ' 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; Actually, TWSocketServer(Sender).ClientCount-1 will be your client number, until one of the client disconnect. Since it's a dynamic array, when a client disconnect, the client number will change. That`s why you need another way to identify your clients. From memory, when my client connected, they would send the server their unique ID and I would store that into a property of the client socket. You have to derive your client socket and add properties to it. Something like : TTcpSrvClient = class(TWSocketClient) public ConnectTime : TDateTime; UniqueID : string; end; then you assign that client socket in the server initialization (in the TcpSrv demo,in WMAppStartup) : WSocketServer1.ClientClass := TTcpSrvClient; { Use our component } Then when I wanted to send a command to a particular client, I would just iterate all connected client searching for the right ID. hth -- 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
Marc, Why we are jumping to the another planet now? We are soo close!! Can you please see the code! This is just getting complicated all the time. Isn't this component having anything such as: CLIENTID?, CLIENTNO?, ID? which could be posted here in the same way as the IP address and the Port? Come on guys, This can't be this complicated! too many opinions but none simple?? Here is what I have, --- procedure TSimpleSslServerForm.SslWSocketServer1ClientConnect( Sender : TObject; Client : TWSocketClient; Error : Word); begin with Client as TTcpSrvClient do begin Display('Client connected.' + '[' + THEID or the CLIENTNUMBER or ANYTHING which helps to identify + ']' + ///Here I need to get this info into the brackets ' 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; Actually, TWSocketServer(Sender).ClientCount-1 will be your client number, until one of the client disconnect. Since it's a dynamic array, when a client disconnect, the client number will change. That`s why you need another way to identify your clients. From memory, when my client connected, they would send the server their unique ID and I would store that into a property of the client socket. You have to derive your client socket and add properties to it. Something like : TTcpSrvClient = class(TWSocketClient) public ConnectTime : TDateTime; UniqueID : string; end; then you assign that client socket in the server initialization (in the TcpSrv demo,in WMAppStartup) : WSocketServer1.ClientClass := TTcpSrvClient; { Use our component } Then when I wanted to send a command to a particular client, I would just iterate all connected client searching for the right ID. hth -- 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] SslWSocketServer SslWSocket
Marc, Why we are jumping to the another planet now? We are soo close!! Can you please see the code! This is just getting complicated all the time. Isn't this component having anything such as: CLIENTID?, CLIENTNO?, ID? which could be posted here in the same way as the IP address and the Port? Come on guys, This can't be this complicated! too many opinions but none simple?? Well, like Francois said, you can use PeerAddr + PeerPort combination to get a unique identifier. I don't think there is a simpler way. But like I said, it's been a long time since I played with that. Sorry if I can't be more helpful. If you REALLY can't figure it out, let me know and I'll play with it to try to find a solution for you. hth -- 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
If you REALLY can't figure it out, let me know and I'll play with it to try to find a solution for you. Thanks Marc, Have been playing 2 days with this and still can't find out the way how to do. -- 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