ESocket_ConnectToHost = &051C00 ESocket_CheckState = &051C01 ESocket_Forget = &051C02 ESocket_SendLine = &051C03 ESocket_ReadLine = &051C04 ESocket_SendData = &051C05 ESocket_ReadData = &051C06 ESocket_Closed = &051C07 ESocket_Listen = &051C08 ESocket_Accept = &051C09 ESocket_ConnectionName = &051C0A ESocket_Monitor = &051C0B ESocket_ResetMonitor = &051C0C ESocket_OurAddress = &051C0D ESocket_DecodeState = &051C0E ESocket_TaskAssociation = &051C0F ESocket_ConnectToAddr = &051C10 r%=0:quit%=FALSE REPEAT r%=FNpoll CASE r% OF WHEN ESocket_ConnectToHost :REM 0x051C00 REM SYS "ESocket_ConnectToHost",host$,port TO handle SYS "ESocket_ConnectToHost",$(datain%+!datain%),datain%!4 TO !dataout% WHEN ESocket_CheckState :REM 0x051C01 REM SYS "ESocket_CheckState",handle TO state REM returns the state of the connection : REM 1 we're looking things up REM 2 we've looked it up and are trying to connect REM 4 we've connected and are ready to go ! REM -1 Host lookup failed (no such host) REM -2 Resolver failure (no response, etc) REM -3 Resolver error (it might not be running !) REM -4 No sockets left to create connection REM -5 Host is unreachable REM -6 Connection refused (not listening on that port) SYS "ESocket_CheckState",!datain% TO !dataout% WHEN ESocket_Forget :REM 0x051C02 REM SYS "ESocket_Forget",handle REM will forget about a handle REM SYS "Esocket_Forget",monitor REM will forget about a monitor. SYS "ESocket_Forget",!datain% WHEN ESocket_SendLine :REM 0x051C03 REM SYS "ESocket_SendLine",handle,string$,flags REM sends a line to the other end; flags are : REM bit 0 set if you DON'T want a CR sending REM bit 1 set if you DON'T want a LF sending REM bit 2 set if the string is terminated by a 13 (otherwise 0) REM this means you'd do something like : REM SYS "ESocket_SendLine",handle,"Hello",%000 REM most of the time, or : REM SYS "ESocket_SendLine",handle,line,%100 REM if you've previously done $line="Hello" SYS "ESocket_SendLine",!datain%,$(datain%+datain%!4),datain%!8 WHEN ESocket_ReadLine :REM 0x051C04 REM SYS "ESocket_ReadLine",handle,buffer,len,flags TO ,buf,len REM which will read a whole line into a buffer, if the buffer REM is not big enough buf is returned as 0 and len as the length REM required, otherwise it's the length of the string. REM return values are therefore : REM buf len REM 0 0 no complete line received yet REM 0 any a line is available of length len (not fitting REM into your buffer) REM any any line of length len was read into your buffer REM any 0 zero length line was read into your buffer REM flags is a similar bit map to SendLine : REM bit 0 & 1 can be : REM %00 to use CR LF as a terminator REM %01 to use LF as a terminator REM %10 to use CR as a terminator REM %11 to use either CR or LF as a terminator REM bit 2 should be set to return the data terminated with 13 REM rather than 0. REM bit 3 should be set to remove characters deleted with codes REM 8 or 127. In this case the returned len is only valid when REM the buffer is. If the buffer is 0, the length is guarenteed REM to be greater than or equal to the true line length. SYS "ESocket_ReadLine",!datain%,datain%!4,datain%!8,datain%!12 TO ,!dataout%,dataout%!4 WHEN ESocket_SendData :REM 0x051C05 REM SYS "ESocket_SendData",handle,buffer,len TO sent REM will send a block of data. The amount of data sent is returned. SYS "ESocket_SendData",!datain%,datain%!4,datain%!8 TO !dataout% WHEN ESocket_ReadData :REM 0x051C06 REM SYS "ESocket_ReadData",handle,buffer,len TO ,,len REM will read a block of data. If buffer = 0 then the length of REM data currently available will be returned in len. If not REM enough data is available then the length of that read is REM returned. SYS "ESocket_ReadData",!datain%,datain%!4,datain%!8 TO ,,!dataout% WHEN ESocket_Closed :REM 0x051C07 REM SYS "ESocket_Closed",handle,flags TO closed REM returns 1 if the socket has been closed, 0 if not REM flags can be set : REM bit 0 will ignore data in the buffer (useful for ReadLine connections) SYS "ESocket_Closed",!datain%,datain%!4 TO !dataout% WHEN ESocket_Listen :REM 0x051C08 REM SYS "ESocket_Listen",port TO handle REM will attempt to listen on a port. However, if an error occurs handle REM will be : REM -4 No sockets left to create connection REM -7 Couldn't listen on that port, something else is REM REM If the port is 0, a new port will be allocated for you. SYS "ESocket_Listen",!datain% TO !dataout% WHEN ESocket_Accept :REM 0x051C09 REM SYS "ESocket_Accept",handle,flags TO newhandle REM will accept a connection on a listening port. REM flags can be : REM bit 0 set to close the listening port after accepting REM newhandle might be returned as : REM -8 Nobody has connected to the port yet SYS "ESocket_Accept",!datain%,datain%!4 TO !dataout% WHEN ESocket_ConnectionName :REM 0x051C0A REM SYS "ESocket_ConnectionName",handle TO name REM will return 0 if no name is known for that connection, or REM the pointer to a zero terminated name otherwise. Connection REM names are resolved multitaskingly. WHEN ESocket_Monitor :REM 0x051C0B REM SYS "ESocket_Monitor",type,... TO monitor REM Monitors are a means by which sockets can be watched for changes without REM having to continually poll them. There can be maybe 'types' of monitors, REM but at present only one is defined : REM type meaning REM 0 checks for input or closure of a socket, and also marks keyboard REM input. Format : REM SYS "ESocket_Monitor",0,handle TO monitor SYS "ESocket_Monitor",!datain%,datain%!4 TO !dataout% WHEN ESocket_ResetMonitor :REM 0x051C0C REM SYS "ESocket_ResetMonitor",monitor,newaddress TO pollword REM is used to reset a monitor back to zero once an active event has been REM identified. If newaddress is 0 then the current address is used. SYS "ESocket_ResetMonitor",!datain%,datain%!4 TO !dataout% WHEN ESocket_OurAddress :REM 0x051C0D REM SYS "ESocket_OurAddress",handle TO ip,port REM will return the address and port number allocated to a socket. Note REM that if you are listening the ip is not likely to be 'correct'. SYS "ESocket_OurAddress",!datain% TO !dataout%,dataout%!4 WHEN ESocket_DecodeState :REM 0x051C0E REM SYS "ESocket_DecodeState",state TO name$ REM will convert the state number into a textual error string that should REM make more sense. WHEN ESocket_TaskAssociation :REM 0x051C0F WHEN ESocket_ConnectToAddr :REM 0x051C10 REM Added 'ConnectToAddr' SWI. REM Detail: REM * ConnectToAddr will connect to a numeric address passed as a parameter, REM which is more useful for things like FTP or IRC. OTHERWISE PRINT "Bad reason code (&"+STR$~r%+")" ENDCASE UN. quit%=TRUE