Sheerpower Logo

Using TCP/IP and UDP Protocols


Using TCP/IP and UDP Protocols

TCP/IP and UDP are two network protocols supported in Sheerpower for sending and receiving data between servers and client computers.

  • TCP/IP is a handshake protocol — data delivery is confirmed, and corrupted packets are re-sent automatically.
  • UDP is a no-handshake protocol — data is sent without confirmation, and reliability must be handled by the application programmer.
Problem: Programs often need reliable communication between machines, but sometimes performance and low latency are more important than guaranteed delivery.

Solution: Use TCP/IP when you need built-in delivery confirmation and retransmission. Use UDP when speed and reduced overhead matter more, and you can manage delivery rules yourself.

Efficiency: TCP/IP provides safety and confirmation, but incurs more overhead. UDP avoids the handshake, which makes it faster and lighter.

Takeaway: Choose the protocol that best fits your application: TCP/IP for reliability, UDP for speed.

TCP/IP vs UDP Overview

TCP/IP (Handshake)

Reliable, connection-oriented. Each message is confirmed by the receiver, and re-sent if corrupted or missing.

Client ---- SYN ----> Server
Client <--- ACK ---- Server
Client ---- DATA --> Server
Client <--- ACK ---- Server

Guarantees delivery with automatic retransmission.

UDP (No Handshake)

Fast, connectionless. Data is sent and may or may not be received. No built-in confirmation or error checking.

Client ---- DATA ----> Server
(no ACK, no retry)

Programmer must handle reliability if needed.

TCP/IP Protocol

Format:

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

Example 18-4: Very Simple TELNET Client

// prompt for IP address 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 (up to 100 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 programmers to transmit data back and forth with built-in confirmation of delivery and automatic re-requests if data is garbled.

Description

If an IP address is specified, it denotes the client machine’s destination. If no IP address is specified, the channel acts as a server. Parameters follow the ? and are separated by &. For example:

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

Table 18-3: TCP/IP Protocol Parameters

ParameterDescriptionDefault
Socketsnumber of sockets to use100
portport number for data transmission31111
ipaddressIP address of the clientnone
max_receive_queuemax number of requests that can be received200
max_send_queuemax number of requests in the send queue200
maxdupconnectionsmaximum duplicate connections allowed3
timeouttimeout length in seconds50

18.4.2 UDP Protocol

Format:

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

Description

If an IP address is specified, it denotes the client destination. Without an IP address, the channel is a server. Parameters follow the ? and are separated by &. For example:

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

Table 18-4: UDP Protocol Parameters

ParameterDescriptionDefault
Socketsnumber of sockets to use100
portport number for data transmission31111
ipaddressIP address of the clientnone
max_receive_queuemax number of requests that can be received200
max_send_queuemax number of requests in the send queue200
maxdupconnectionsmaximum duplicate connections allowed3
timeouttimeout length in seconds50
(Show/Hide Sheerpower TCP/IP & UDP Protocol Takeaways)
Hide Description

    

       


      

Enter or modify the code below, and then click on RUN

Looking for the full power of Sheerpower?
Check out the Sheerpower website. Free to download. Free to use.