TCP Echo socket

The Echo server just returns anything it receives to the sender. It is a simple test of TCP transmission and reception. Only one connection at a time is supported.

To save code space, the Echo server uses the server system in SERVICES\Servers.fth and Saccept from the BSD layer.

As discussed in the Telnet chapter, HyperTerminal PE is a reasonable test client.

TCP_PSH value EchoFlags \ -- n
For fast response for use with an interactive terminal set this to TCP_PUSH. For fast bulk response, set this to zero.

7 equ EchoPort# \ -- n
Port on which Echo server listens. Moved to PNconfig.fth.

$100 equ EBLen  \ -- n
Size of the Echo receive buffer.

EBLen buffer: EchoBuffer        \ -- addr
The Echo receive buffer.

#60000 equ /EchoMs      \ -- ms
Max delay after a connection before the socket is closed if there is no transmission.

: echoEst?      \ hs -- flag
Return true if the socket is in ESTABLISHED state.

: echoWait      \ hs -- flag
Wait for something to be received up to the timeout period. Flag is returned true if the socket is still ESTABLISHED and there has been no timeout.

: echoResponse  \ hs --
Read the input and respond.

: echoClose     \ hs --
Close the echo connection.

: EchoService   \ hs --
Service an Echo connection.

: DoRunEchoSocket       \ --
The Echo task.

task TcpEchoTask        \ -- addr
The task running the Echo socket.

: RunEchoSockTask       \ --
Start the Echo task.