
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%
Содержание BHT-BASIC 100 SERIES
Страница 1: ......
Страница 161: ...153 Chapter 10 Sleep Function CONTENTS 10 1 Sleep Function 154...
Страница 163: ...155 Chapter 11 Resume Function CONTENTS 11 1 Resume Function 156...
Страница 173: ...165 Chapter 13 Backlight Function CONTENTS 13 1 Backlight Function 166...
Страница 192: ...Chapter 14 Statement Reference 184 Example OPEN master Dat AS 1 FIELD 1 20 AS bar 10 AS ky CLFILE 1 CLOSE 1...
Страница 249: ...241 Example CLOSE IF kyIn Y THEN KILL Master Dat END IF Reference Statements CLFILE...
Страница 349: ...341 Run time errors Error code Meaning 05h Parameter out of the range checktype is out of the range...
Страница 383: ...375 Run time errors Reference Error code Meaning 05h Parameter out of the range Functions LEFT LEN and RIGHT...