3
include(navbar.html.m4)
5
TITLE(Layer one: protocol abstraction)
7
Skip this layer if you really want to use Armagetron's networking system
8
fast; it contains details you do not need to know from the start.
11
This layer is responsible for sending raw data packets to other computers.
12
The files <CODE>net_anet.h,net_sysdep.C,net_udp.C</CODE> and
13
<CODE>net_wins.C</CODE> are responsible for it;
14
they are written in pure C.
15
<CODE>net_anet.h</CODE> is the header file with the declarations visible to
16
layer two, and <CODE>net_systep.C</CODE> just includes the real
17
implementation from <CODE>net_udp.C</CODE> or <CODE>net_wins.C</CODE> depending
18
on the system Armagetron is compiled for.
21
SECTION(Data structures)
24
CODEITEM(sockaddr,struct sockaddr:,
25
[Everything the network protocol needs to identify
26
a connection to another computer. In the case of UDP, it contains the IP
27
address and port number.])
29
CODEITEM(socket,Sockets:,
30
[represented by integers: in analogy to file descriptors,
31
all network IO is done
32
through sockets. Every client has one socket where all the messages to/from
33
the server are sent/received through. The server has one listening socket for
34
the messages from new clients, and one IO socket for each client.
35
(With the UDP protocol, all these sockets are really identical, as there is
36
no such thing as a connection and no need/possibility to assign a connection
40
SECTION(Function list)
41
(only the functions layer two actually uses are mentioned)
44
CODEITEM(init,Socket ANET_Init();,[Initialises the network system, returns the
45
control socket. All future IO is done through that socket.])
47
CODEITEM(shutdown,void ANET_Shutdown (void);,Closes the network system.)
49
CODEITEM(listen,void ANET_Listen(bool state);,[If state is true, the listening
50
socket is initialised (listening at the port ]<CODE>net_hostport=4532</CODE>[)
51
and can be queried by]
52
<CODE>ANET_CheckNewConnections</CODE>.)
54
CODEITEM(checknewconnections,Socket ANET_CheckNewConnections (void);,
55
[On the server, this checks if there are any new connections
56
from clients wanting to join the game. Returns a socket ready to receive
57
the newcomer if there is one, or -1 if not. In case of the UDP protocol,
58
even the messages from the known clients are caught by this function
59
(as there is no way to distinguish new and old connections with UDP), so layer
60
two needs to do some extra checks with this function.
63
CODEITEM(getaddrfromname,[int ANET_GetAddrFromName
64
(const char *name, struct sockaddr *addr);],[
65
Fills <CODE>*addr</CODE> with the information necessary to reach the server
66
<CODE>name</CODE> (containing the IP address in numerical notation or the
68
the port number is set to ]<CODE>net_hostport=4532</CODE> to match the port
69
the server listens on.)
71
CODEITEM(connect,ANET_Connect(Socket s,struct sockaddr *addr);,[
72
Opens a connection to the computer given by ]<CODE>addr</CODE>[ through
73
the socket] <CODE>s</CODE>.
74
[As UDP is a connectionless protocol, this does not do
77
CODEITEM(write,int ANET_Write (Socket sock, const byte *buf, int len, struct sockaddr *addr);,
78
Sends <CODE>len</CODE> bytes of data from <CODE>buf</CODE> through the socket
79
<CODE>sock</CODE> to the peer identified with <CODE>*addr</CODE>. A connection
80
has to be established before with <CODE>ANET_Connect()</CODE>.)
82
CODEITEM(read,int ANET_Read (Socket sock, byte *buf, int len, struct sockaddr *addr);,
83
Reads up to <CODE>len</CODE> bytes from the connection associated to
84
socket <CODE>sock</CODE> and stores them in the buffer <CODE>buf</CODE>.
85
[(If a connectionless protocol like UDP is used and the socket is a listening
86
socket, this can mean ANY data coming in at the port the socket listens on...)
87
]The sender's address is stored in <CODE>*addr</CODE>[, the number of actually
88
read bytes is returned (Zero means no data was received.)])
90
CODEITEM(addrtostring,char *ANET_AddrToString (const struct sockaddr *addr);,[
91
Returns the information from ]<CODE>addr</CODE>[ in human readable form.])
93
CODEITEM(addrcompare,int ANET_AddrCompare (struct sockaddr *addr1, struct sockaddr *addr2);,
94
Checks whether <CODE>*addr1</CODE> and <CODE>*addr2</CODE> [are the same
95
computer (ignoring the port number). If they are, 0 is returned, -1 if not.])
97
CODEITEM(getsocketport,int ANET_GetSocketPort (struct sockaddr *addr),
98
Returns the port number from <CODE>*addr</CODE>.)
104
include(navbar.html.m4)