Sheerpower®
A Guide to the Sheerpower Language


Previous Contents Index

18.4 Using TCP/IP and UDP Protocols

TCP/IP and UDP protocols are specific methods used to send data back and forth from a server to a client computer.

The difference between TCP/IP and UDP is:

With TCP/IP, the handshake means that if one machine sends another some data, the receiving machine sends back a data packet that tells the sending machine the data was received. If the receiving machine requests that the sending machine then confirm that their confirmation packet was received, the sending machine sends a data packet back, and so on.

If the receiving machine receives garbled or otherwise messed up data, it will automatically re-request the data from the sending machine.

UDP is not a handshake protocol... there is no guarantee of data delivery. The data gets sent, and that is it. The receiving machine may or may not successfully receive the data, but the sender doesn't get any confirmation. The programmer has to create the rules for UDP protocol to get responses back from the recipient machine.

18.4.1 TCP/IP Protocol

FORMAT:


  open file tcp_ch: name 'tcp://[ip]?[param1=value1]&[param2=value2]&[paramn=valuen]', access outin 

EXAMPLE:

Example 18-4 TCP/IP Protocol

// Very simple TELNET client 
line input 'IP address of the telnet server': ip$ 
 
open file tcp_ch: name 'tcp://' + ip$ + '?port=23', access outin 
print 'Ready for data...' 
 
do 
  // check for data from the server 
  // but not forever... just a few iterations 
  for idx = 1 to 100 
    line input #tcp_ch: ip$ 
    if ip$ = '' then exit for 
    ask #tcp_ch, symbol 'data': value rec$ 
    print rec$; 
  next idx 
  
  // check for data from this client 
  when exception in 
    key input timeout 1, prompt '': dat$ 
    print #tcp_ch: dat$ 
  use 
  end when 
 
loop 
end 

PURPOSE:

TCP/IP allows the programmer to transmit data back and forth from one computer to another with the capability of receiving responses and data transmission confirmation.

DESCRIPTION

If an IP address is specified, then it denotes the receive source IP and the send destination IP for a client.

If no IP address is specified, the channel is a server.

The start of the options list begins with a ? (question mark), and each parameter is separated by an & (ampersand). The options are NAMED as outlined in the table below. For example, if you wanted to specify "port 23", you would use:

Example 18-5 TCP/IP Protocol - Port Parameter

  open file tcp_ch: name 'tcp://' + '?port=23', access outin 

Table 18-3 TCP/IP Protocol Parameters
Parameter Description Default
Sockets specifies the number of sockets to use 100
port specifies the port number to be used for transmitting data 31111
ipaddress the IP address of the CLIENT machine receiving data none
max_receive_queue specifies the max number of requests able to be received at once 200
max_send_queue specifies the max number of requests allowed in the send queue 200
maxdupconnections specifies the maximum duplicate connections allowed 3
timeout specifies the length of timeout in seconds 50

18.4.2 UDP Protocol

FORMAT:


  open file udp_ch: name 'udp://[ip]?[param1=value1]&[param2=value2]&[paramn=valuen]', access outin 

DESCRIPTION

If an IP Address is specified, then it denotes the receive source IP and the send destination IP for a client.

If no IP address is specified, the channel is a server.

The start of the options list begins with a ? (question mark), and each parameter is separated by an & (ampersand). The options are NAMED as outlined in the table below. For example, if you wanted to specify a "timeout of 20 seconds", you would use:


  open file udp_ch: name 'udp://' + '?timeout=20', access outin 

Table 18-4 UDP Protocol Parameters
Parameter Description Default
Sockets specifies the number of sockets to use 100
port specifies the port number to be used for transmitting data 31111
ipaddress the IP address of the CLIENT machine receiving data none
max_receive_queue specifies the max number of requests able to be received at once 200
max_send_queue specifies the max number of requests allowed in the send queue 200
maxdupconnections specifies the maximum duplicate connections allowed 3
timeout specifies the length of timeout in seconds 50

18.5 Communication Port Support

FORMAT:


  open #n: name "com://port=p?options", access outin 

EXAMPLE:

The example below is not a 'runnable' example. It is intended only to illustrate how to use the communication support in Sheerpower.

Example 18-6 Communication Port

  // use com4 port for talking to some device 
  open file com_ch: name 'com://port=4', access outin 
  print #com_ch: 'AT' 
  line input #com_ch: cdata$ 
  if cdata$ <> '' then print 'Response was: '; cdata$ 
  end 

PURPOSE:

Communication (COM) Port Support is available to access the serial communication ports on a computer.

DESCRIPTION

The port number p is required. i.e., 1, 2, 3, etc.

The start of the options list begins with a ? (question mark), and each parameter is separated by an & (ampersand). The options are NAMED as outlined in the table below. For example, if you wanted to specify "7-bits", you would use:

Example 18-7 Communication Port

  com://port=4?speed=9600&bits=7 

Table 18-5 Communication Port Options
Option Description Default Value
SPEED specifies baud rate 9600 110, 300, 600, 1200, 2400, 4800, 9600, 14400, 19200, 38400, 56000, 128000, 256000
BITS specifies number of bits 8 5, 6, 7, 8
PARITY specifies parity used off off, even, odd, mark, space
STOPBITS specifies number of stop bits 1 1, 1.5, 2
DSRDTR specifies dsr/dtr protocol off on, off
RTSCTS specifies rts/cts protocol off on, off
XONXOFF specifies xon/xoff protocol off on, off

If the baud or bit value is invalid, the default value is used.


Previous Next Contents Index