Difference between revisions of "TWSocket.SendStr"

From Overbyte
Jump to navigation Jump to search
(first Entry)
 
 
Line 19: Line 19:
 
   MySocket.Addr:='192.168.0.1';
 
   MySocket.Addr:='192.168.0.1';
 
   MySocket.Port:='1234';
 
   MySocket.Port:='1234';
 
+
 
 
   MySocket.Connect;
 
   MySocket.Connect;
 
+
 
 
   s:='Hello World';
 
   s:='Hello World';
 
   MySocket.SendStr(s);
 
   MySocket.SendStr(s);
 
+
 
 
   MySocket.Close;
 
   MySocket.Close;
 
   MySocket.Free;
 
   MySocket.Free;

Latest revision as of 10:53, 5 October 2006

Main page -> ICS component reference -> TWSocket -> SendStr

Definition

method SendStr(Str:String): integer;

Description

SendStr sends the data provided in Str to the socket connected with this TWSocket. For UDP connections no explicit connection exists, for TCP connections a connection must be established before SendStr may be used.

Example

The following example establishes a TCP client connection to another socket at 192.168.0.1:1234 and sends the string Hello World to it. Afterwards the connection is closed and the socket is freed.

 var MySocket:TWSocket;
     s       :String;
 
 MySocket:=TWSocket.Create(nil);
 MySocket.Proto:='tcp';
 MySocket.Addr:='192.168.0.1';
 MySocket.Port:='1234';
 
 MySocket.Connect;
 
 s:='Hello World';
 MySocket.SendStr(s);
 
 MySocket.Close;
 MySocket.Free;

Best practices

How to

  • for sending strings in line mode you must remember to manually attach the defined delimiter to the end of your string