Specifications

Chapter 18. TCP/IP
453
18.4.2 Client Program Samples for Socket API
According to TCP and UDP
This section gives TCP and UDP client program samples. With ON ERROR GOTO statement,
you may trap errors if happened during execution of functions used in these samples.
These samples show only the skeleton of communication programs and require modification in
actual programming as necessary.
TCP client program
(Example)
****************************************
Data Section *
****************************************
DIM RECVBUFF$[255] Receive data buffer
DIM SENDBUFF$[255] Send data buffer
DIM IPADDRESS$[15] IP address
DIM R.SOCKSET$[41] Read socket ID set
DIM W.SOCKSET$[41] Write socket ID set
DIM E.SOCKSET$[41] Exception socket ID set
************************************************
Sample subroutine for TCP client *
************************************************
TCPCLIENT:
Create send data
FOR I%=0 TO 254 STEP 1
SENDBUFF$[I%] = CHR$(I%)
NEXT I%
Create TCP socket <-----Equivalent to BSD4.4 socket API () function
FAMILY% = 2 Internet protocol
TYPE% = 1 Stream socket
PROTOCOL% = 6 TCP protocol
CALL "SOCKET.FN3" .fcSocket FAMILY%, TYPE%, PROTOCOL%, SOCKFD%
Convert IP address <----- Equivalent to BSD4.4 socket API inet_addr() function
IPADDRESS$ = "192.100.100.001" Specify server IP address
CALL "SOCKET.FN3" .fcINetAdr IPADDRESS$, ADDRESS
Connect socket to server <----- Equivalent to BSD4.4 socket API connect() function
PORT% = 1201 Specify server port
CALL "SOCKET.FN3" .fcConnect SOCKFD%, FAMILY%, PORT%, ADDRESS
Transmit data <----- Equivalent to BSD4.4 socket API send() function
SENDLEN% = 255
SENDMODE% = 0
CALL "SOCKET.FN3" .fcSend SOCKFD%, SENDBUFF$, SENDLEN%, SENDMODE%,
SENDSIZE%