TWSocket.SendStr

From Overbyte
Jump to: navigation, search

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