Specifications
448
18.3.4 Sample Program
Given below is a sample program that shows only the skeleton of communication program and
requires modification in actual programming as necessary.
’****************************************
’ 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%
TCP.STTS% = 0
ON ERROR GOTO 0 ’Disable error trapping
ON ERROR GOTO TCP.ERR ’Enable error trapping
’Set TCP/IP parameters
IFTYPE% = 0 ’Specify COM1
LAYERMODE% = 2 ’Specify Ethernet
CALL "SOCKET.FN3" .fcTSetup IFTYPE%, LAYERMODE%, INTERFACE%
’Open IrDA communications device
TCP.OPEN:
OPEN "COM1:115200" AS #1 ’Open COM1
TCP.STTS% = 1
’Connect to TCP/IP communications pathway (with user settings)
CALL "SOCKET.FN3" .fcTCnnUsr INTERFACE%, MY.ADDR$, SUBNETMASK$, GATEWAY$
TCP.STTS% = 2
’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%