> socket709.port:='709'; > socket709.address:='127.0.0.1'; // for now my own IP is enough to > test with > socket709.connect; > socket709.sendstr(#13); > > but this always generates an exception from ICS. No matter what I do > I can't make it work.
The only thing you haven't seen is the asynchronous nature of ICS. For example, when you call Connect, you get control back immediateley (that is the next line is executed), while the connection is establishing, maybe slowly, in the background. Once tthe connection is established, you get the OnSessionConnected event triggered. The component is only able to handle a single task at a given instance. So if you asked to connect, it can't do anything else while connecting (well, you can abort). So when you cann SendStr at the line next to connect, the component raise an exception telling you it is busy. You can send data only once the connection is successfuly established, that is when you received the OnSessionConnected event with a nul error argument. What you have to do: Drop a TWSocket (let's call it Socket709), TButton and TMemo on a form. In the button onclick event, put this code: begin socket709.port:='709'; socket709.address:='127.0.0.1'; socket709.protocol := 'tcp'; socket709.connect; Memo1.Lines.Add('Connecting...'); end; in the socket session connected event, put this code: begin if Error <> 0 then Memo1.Lines.Add('Failed, error #' + IntToStr(Error)) else begin Memo1.Lines.Add('Connected, sending data'); socket709.SendStr('Hello World !' + #13#10); end; end; in socket datavailable event, put this code: begin Memo1.Lines.Add('Received "' + socket709.ReceiveStr + '"'); end; Hope this helps... btw: Next time, use a better subject in your message to reflect what you are asking -- [EMAIL PROTECTED] http://www.overbyte.be ----- Original Message ----- From: "A Question" <[EMAIL PROTECTED]> To: <twsocket@elists.org> Sent: Saturday, August 13, 2005 7:14 PM Subject: [twsocket] (no subject) > My problem is so simple I'm embarrassed to ask. No doubt it's > completely my fault. I'm struggling with ICS because the software > comes with no 'user guide', no short examples, and even finding > examples on the internet less than 1000 lines of code is hard. > Despite those shortcomings I'm still very impressed with ICS and I > want to thank Francois for it. > > Here's my problem: I just want to test if a server on my network is > running. So I essentially want to test if the server is responding to > a specific port, which is 709. So I write the following code: (not > sure if this fragment is enough, but it may be) > > socket709.port:='709'; > socket709.address:='127.0.0.1'; // for now my own IP is enough to > test with > socket709.connect; > socket709.sendstr(#13); > > but this always generates an exception from ICS. No matter what I do > I can't make it work. I've been testing it using port 80 on known web > servers and that also fails. > > > -- > To unsubscribe or change your settings for TWSocket mailing list > please goto http://www.elists.org/mailman/listinfo/twsocket > Visit our website at http://www.overbyte.be -- To unsubscribe or change your settings for TWSocket mailing list please goto http://www.elists.org/mailman/listinfo/twsocket Visit our website at http://www.overbyte.be