Sim68K Network I/O
TCP
TCP (Transmission Control Protocol) provides reliable delivery of data.
Large messages are automatically broken into smaller IP-sized packets,
transmitted, received and reassembled in order by the receiver. Packets that are
lost during transmission are automatically retransmitted. The reliability of TCP
message delivery can result in long delays (on the order of seconds) if packets
are lost and must be retransmitted. For this reason TCP is typically not
considered suitable for the delivery of real-time data. TCP establishes a
connection between the two devices. This connection is maintained until broken
by one or both devices. In EASy68K only one TCP
connection is permitted at a time. If the other host breaks the connection an
error will result when attempting to send or receive data. Refer to the error
codes below.
UDP
UDP (User Datagram Protocol)
is a connectionless protocol that does not guarantee data delivery. Data packets
may arrive out of order, be duplicated, or not delivered at all. UDP is
typically used for time sensitive applications where timely delivery of data is
more important than reliability. Because of it's connectionless nature a UDP server may receive transmissions from multiple UDP clients.
EASy68K uses non-blocking sockets which means all of the network trap tasks return immediately. Check the Post register contents to determine the results.
TRAP #15 is used for I/O. Put the task number in lower 8 bits of D0.
Task
100 |
Configure as network Client. Pre: D1.L {31..............16}{15......8}{7......0} Bits 0-7, 0 for UDP, 1 for TCP, all other values reserved Bits 8-15, Reserved for future use Bits 16-31, Port number Port numbers 0-1023 are used for well-known services. Port numbers 1024-65535 may be freely used. (A2) IP address to connect to as null terminated string (e.g. '192.168.1.100',0) or null terminated domain name (e.g. 'www.easy68k.com',0) Post: D0.L is 0 on success, non zero on error Error codes: Bits 0-15 Low word of D0 1 - general error 2 - network initialization failed 3 - invalid socket 4 - get host by name failed 5 - bind failed 6 - connect failed 7 - port already in use 8 - domain not found All other values reserved Bits 16-31 High word of D0, extended error code (see below) (A2) IP address connected to as null terminated string Example:
move.b #100,d0
; create network client
serverIP dc.b '192.168.1.101',0 Visit www.EASy68K.com for examples. |
101 |
Configure as network Server. May not be configured as Server and Client at the same time. Pre: D1.L {31..............16}{15......8}{7......0} Bits 0-7, 0 for UDP, 1 for TCP, all other values reserved Bits 8-15, Reserved for future use Bits 16-31, Port number Port numbers 0-1023 are used for well-known services. Port numbers 1024-65535 may be freely used. Post: D0.L is 0 on success, non zero on error Error codes: Bits 0-15 Low word of D0 1 - general error 2 - network initialization failed 3 - invalid socket 4 - get host by name failed 5 - bind failed 6 - connect failed 7 - port already in use 8 - domain not found All other values reserved Bits 16-31 High word of D0, extended error code (see below) |
102 |
Send data. (Deprecated, use 106) Pre: D1.L {31..............16}{15..............0} Bits 0-15, Number of bytes to send Bits 16-31, Reserved for future use (A1) data to send If server (A2) IP address of client as null terminated string (e.g. '192.168.1.100',0) Post: D0.L is 0 on success, non zero on error. Success does not indicate data was sent. Bits 0-15 Low word of D0 1 - send failed All other values reserved Bits 16-31 High word of D0, extended error code (see below) D1.L number of bytes sent. 0 if no data was sent. Unchanged on error. |
103 |
Receive data. (Deprecated, use 107) Pre: D1.L {31..............16}{15..............0} Bits 0-15, Number of bytes to receive. Bits 16-31, Reserved for future use. (A1) received buffer, must be large enough to hold D1.W bytes. Post: D0.L is 0 on success, non zero on error. Success does not indicate data was received. Bits 0-15 Low word of D0 1 - receive failed All other values reserved Bits 16-31 High word of D0, extended error code (see below) D1.L number of bytes received. 0 if no data has been received. Unchanged on error. (A2) IP address of sender as null terminated string. |
104 |
Close connections Pre: If TCP server D1.L IP address of connection to close, 0 to close all. Post: D0.L is 0 on success, non zero on error Bits 0-15 Low word of D0 1 - close failed All other values reserved Bits 16-31 High word of D0, extended error code (see below) |
105 |
Get local IP address Pre: The network has been initialized with task 100 or 101 Post: D0.L is 0 on success, non zero on error Bits 0-15 Low word of D0 1 - get local IP failed All other values reserved Bits 16-31 High word of D0, extended error code (see below) (A2) local IP address as null terminated string. Max size 16 characters including null. |
106 |
Send data on specified port. Pre: D1.L {31..............16}{15..............0} Bits 0-15, Number of bytes to send Bits 16-31, Port number Port numbers 0-1023 are used for well-known services. Port numbers 1024-65535 may be freely used. (A1) Data to send If server (A2) IP address of client as null terminated string (e.g. '192.168.1.100',0) Post: D0.L {31..............16}{15..............0} Bits 0-15, 0 on success, non zero on error. Success does not indicate data was sent. 1 - Send failed All other values reserved Bits 16-31 Extended error code (see below) D1.L {31..............16}{15..............0} Bits 0-15, Number of bytes received. 0 if no data has been received. Unchanged on error. Bits 16-31, Reserved for future use |
107 |
Receive data and port number Pre: D1.L {31..............16}{15..............0} Bits 0-15, Number of bytes to receive. Bits 16-31, Reserved for future use. (A1) received buffer, must be large enough to hold D1.W bytes. Post: D0.L {31..............16}{15..............0} Bits 0-15, 0 on success, non zero on error. Success does not indicate data was received. 1 - receive failed All other values reserved Bits 16-31 High word of D0, extended error code (see below) D1.L {31..............16}{15..............0} Bits 0-15, Number of bytes received. 0 if no data has been received. Unchanged on error. Bits 16-31, Port number of received data (A2) IP address of sender as null terminated string. |
Extended Error Codes in high word of D0
$2714 - A blocking operation was interrupted
$271D - Socket access permission violation
$2726 - Invalid argument
$2728 - Too many open sockets
$2735 - Operation in progress
$2736 - Operation on non-socket
$2737 - Address missing
$2738 - Message bigger than buffer
$273F - Address incompatible with protocol
$2740 - Address is already in use
$2741 - Address not valid in current context
$2742 - Network is down
$2743 - Network unreachable
$2744 - Connection broken during operation
$2745 - Connection aborted by host software
$2746 - Connection reset by remote host
$2747 - Insufficient buffer space
$2748 - Connect request on already connected socket
$2749 - Socket not connected or address not specified
$274A - Socket already shut down
$274C - Operation timed out
$274D - Connection refused by target
$274E - Cannot translate name
$274F - Name too long
$2750 - Destination host down
$2751 - Host unreachable
$276B - Network cannot initialize, system unavailable
$276D - Network has not been initialized
$2775 - Remote has disconnected
(Refer to Winsock file winerror.h for unlisted error codes )