RtTcpipServer

The RtTcpipServer sample creates a socket at the specified port. How this port gets used depends upon whether the server is operating in UDP or TCP mode.

If operating in TCP mode, the main thread listens on this socket, accepts connections from clients and, by default, creates a new thread for each accepted connection to echo packets received on that connection. Multi-threaded operation of TCP can be disabled by a command line option. If operating in single threaded mode, new connections from clients are not accepted until the previous client has shut down its connection.

If operating in UDP mode, the main thread of server uses this socket to receive packets from all clients and to echo the packet back to the sender. UDP mode implies single threaded operation.

If a UDP socket is not bound to an IP address, and the system has configured several IP addresses on the same subnet as the destination IP address (or the route to the destination), UDP datagrams will be sent using the first IP address configured for this subnet.

The server sample runs indefinitely after it starts. To terminate the server, it must be killed with either the Windows Task Monitor (EXE images) or with RtssKill (RTSS images).

The RtTcpipServer sample registers a shutdown handler with RTSS so that it can continue to run after a Windows Shutdown event. Once a shutdown has occurred, the server switches to single threaded mode to permit connections to be accepted and serviced without the need to create a new thread.

The various command line options are described below.

RTSS Usage

RTSSrun rttcpipserver.rtss [options]

Windows Usage

rttcpipserver.exe [options]

Options

Option Description

i=

Source IP address in dot notation (if needed)

f=v4,v6

v4= IPv4(AF_INET) as address family

v6= IPv6(AF_INET6) as address family

Note: This is required for IPv6 addresses if the i= option is not specified.

n=0,1

0=disable Nagle Algorithm (default), 1=Enable Nagle Algorithm

Note: Both the client and the server must have the use of the Nagle Algorithm in the same state. Either both have the Nagle Algorithm disabled or both have the Nagle Algorithm enabled.

p=nn

Port number (default is 9999)

r=nn

Report processed packets at an interval of every nn number of loops (default is 500)

/udp

Use UDP instead of defaulting to TCP

/s

Use single threading (multi-threaded is the default)

/silent

No printouts will occur after initialization

t=nn

Select timeout in ms. used with UDP send (default is 1000)

w=nn

Socket window size (SO_SNDBUF and SO_RCVBUF) options

/?

Displays usage

Output

In TCP mode (default), the console output should look like this:

*** RtTcpipServer Application ***
*** TCP/IP WinSock started ***
*** TimeStamp is Disabled ***
*** Nagle Algorithm is Disabled ***
*** Socket buffer size 500000 ***
*** TCP/IP stack listening on socket 1, port 9999 ***
Main Thread: connection on sd_accept = 2
Connected to 192.168.200.199 on port 39286
Connected locally (192.168.200.1) on port 9999
ServiceTcpClient entered (2) ***
Client thread started on connection(2)
port 9999 - 500 packets processed
port 9999 - 1000 packets processed
port 9999 - 1500 packets processed
port 9999 - 2000 packets processed
port 9999 - 2500 packets processed
port 9999 - 3000 packets processed
port 9999 - 3500 packets processed
port 9999 - 4000 packets processed
port 9999 - 4500 packets processed
port 9999 - 5000 packets processed
port 9999 - 5500 packets processed
port 9999 - 6000 packets processed
port 9999 - 6500 packets processed
port 9999 - 7000 packets processed
port 9999 - 7500 packets processed
port 9999 - 8000 packets processed
port 9999 - 8500 packets processed
port 9999 - 9000 packets processed
port 9999 - 9500 packets processed
port 9999 - 10000 packets processed
port 9999 - 10500 packets processed
Socket (2) shut down
*** Socket(2) Closed on port 9999, 10500 packets processed ***

In UDP mode, the console output should look like this:

*** Using UDP ***
*** RtTcpipServer Application ***
*** TCP/IP WinSock started ***
*** Socket buffer size 500000 ***
ServiceUdpClient entered (3) ***
port 9999 - 500 packets processed
port 9999 - 1000 packets processed
port 9999 - 1500 packets processed
port 9999 - 2000 packets processed
port 9999 - 2500 packets processed
port 9999 - 3000 packets processed
port 9999 - 3500 packets processed
port 9999 - 4000 packets processed
port 9999 - 4500 packets processed
port 9999 - 5000 packets processed
port 9999 - 5500 packets processed
port 9999 - 6000 packets processed
port 9999 - 6500 packets processed
port 9999 - 7000 packets processed
port 9999 - 7500 packets processed
port 9999 - 8000 packets processed
port 9999 - 8500 packets processed
port 9999 - 9000 packets processed
port 9999 - 9500 packets processed
port 9999 - 10000 packets processed
port 9999 - 10500 packets processed

APIs Referenced

RTAPI

Supported Windows API

Winsock BSD API

Related topics: