TCP/IP functions

TCP/IP functions. More...

Functions

 tcp_srv_open (port)
 Open a TCP/IP server.

 tcp_srv_close ()
 Close TCP/IP server.

 tcp_srv_read ()
 Get received data from the TCP/IP server buffer.

 tcp_srv_write (data)
 Write to the connected client.

 tcp_srv_hasclient ()
 Verify if is a client connected to the TCP/IP server.

 tcp_srv_flush ()
 Flush TCP/IP server receive buffer.

 tcp_srv_flush (char_no)
 Partially flush TCP/IP server receive buffer.

 tcp_open (addr, port)
 Open a TCP/IP client connection.

 tcp_close ()
 Close TCP/IP client connection.

 tcp_read ()
 Get received data from the TCP/IP client buffer.

 tcp_write (data)
 Send data to the server where client is connected.

 tcp_flush ()
 Flush TCP/IP client receive buffer.

 tcp_flush (char_no)
 Partially flush TCP/IP client receive buffer.

 tcp_isconnected ()
 Verify client connection state.


Detailed Description

TCP/IP functions.


Function Documentation

tcp_close  ) 
 

Close TCP/IP client connection.

Closes current TCP/IP client connection.

tcp_flush char_no   ) 
 

Partially flush TCP/IP client receive buffer.

Flushes only first char_no characters (bytes) of TCP/IP client input buffer.
This is useful when making decisions based on received data, for example when waiting for CRLF terminated strings. Flushing the buffer after use of data will have only fresh data in the buffer.

Parameters:
char_no How many characters (bytes) to delete
Note:
Use this version of flush to prevent data loss between receive and flush actions.

tcp_flush  ) 
 

Flush TCP/IP client receive buffer.

Flushes TCP/IP client input buffer.
This is useful when making decisions based on received data, for example when waiting for CRLF terminated strings. Flushing the buffer after use of data will have only fresh data in the buffer.

Note:
Use tcp_flush(char_no) instead.

tcp_isconnected  ) 
 

Verify client connection state.

Verify connection state, returns "1" if connected, "0" otherwise.

Example:
state=tcp_isconnected()
if (state==1)
tcp_write("a message from me")
endif

tcp_open addr  ,
port 
 

Open a TCP/IP client connection.

This function will try to open a TCP/IP client connection to the specified IP address and port, and is NOT BLOCKING, so the script resumes immediatly.
To check if the connection succeded use the isconnected function (within a timeout block if required).

Parameters:
addr IP Address of the remote server
port Port on the remote server

tcp_read  ) 
 

Get received data from the TCP/IP client buffer.

Get received data from the TCP/IP client buffer.
The return value will contain all data received since the client connected or the buffer was flushed.
The call to the function must be done exactly when data is needed.

Note:
Some sort of protocol must be implemented, if not is possible to loose data.

tcp_srv_close  ) 
 

Close TCP/IP server.

Closes current TCP/IP server, freeing port number.

tcp_srv_flush char_no   ) 
 

Partially flush TCP/IP server receive buffer.

Flushes only first char_no characters (bytes) of TCP/IP server input buffer.
This is useful when making decisions based on received data, for example when waiting for CRLF terminated strings. Flushing the buffer after use of data will have only fresh data in the buffer.

Parameters:
char_no How many characters (bytes) to delete
Note:
Use this version of flush to prevent data loss between receive and flush actions.

tcp_srv_flush  ) 
 

Flush TCP/IP server receive buffer.

Flushes TCP/IP server input buffer.
This is useful when making decisions based on received data, for example when waiting for CRLF terminated strings. Flushing the buffer after use of data will have only fresh data in the buffer.

Note:
Use tcp_srv_flush(char_no) instead.

tcp_srv_hasclient  ) 
 

Verify if is a client connected to the TCP/IP server.

Verify if is a client conected, returns its address if there is, empty string otherwise.

Example:
addr=tcp_srv_hasclient ()
laddr=len (addr)
if (laddr>>0)
writelog ("Client connected: "&addr)
endif

tcp_srv_open port   ) 
 

Open a TCP/IP server.

Opens a TCP/IP server listening on specified port.
Only one client connection is accepted at a time.

Parameters:
port Port number where server will listen
Note:
If a client silently dies the server may not be aware of this and will be locked on this "zombie" connection. You must implement some sort of watchdog with a timer, for example if data is not received from a client for more than 5 minutes consider the connection lost and restart the server.
Example: tcp_srv_open(5001)

tcp_srv_read  ) 
 

Get received data from the TCP/IP server buffer.

Get received data from the TCP/IP server buffer.
The return value will contain all data received since the server was opened or the buffer was flushed.
The call to the function must be done exactly when data is needed.

Note:
Some sort of protocol must be implemented, if not is possible to loose data.

tcp_srv_write data   ) 
 

Write to the connected client.

Sends data to the connected client.

Parameters:
data Data to be sent

tcp_write data   ) 
 

Send data to the server where client is connected.

Sends data to the server where client is connected.

Parameters:
data Data to be sent


Generated on Wed Dec 3 10:18:42 2003 for Easy Control