The routines you will write are for the sending entity (the client) and the receiving entity (the server). You must simulate data transfer (from client to server) and (positive or negative) acknowledgment from the server to client. Such routines would in real-life be part of the operating system, and would be called by other routines in the operating system.
The functions you will write will be called by (and will call) network emulation routines in the KRnet files. The network emulation routines have been written for you — you do not need to read them or understand how they work.
All of the client functions are to be defined in the client.c file. Those functions are:
void clientInit(void)
The simulation will call this function only once, before any of your other sending-side routines are called. It can be used to do any initialization you think is needed.
void clientEnd(void)
The simulation will call this function only once. It is the last
function called. It can be used to clean-up any state that you
have, for instance if you are using a file to hold debugging
output then you might open the file in clientInit()
and close it here.
void clientOutput(message_t msg)
msg
is a message containing data to be
sent to the server-side of the connection.
The simulated operating system will call this function will be
called whenever the upper layer at the sending side
(Client
) has a message to send. It is the job of your
protocol to ensure that the data in such a message is delivered
in-order, and correctly, to the receiving side's application
layer.
void clientInput(packet_t pkt)
pkt
is a (possibly corrupt) packet from the
server-side of the connection
The simulation will call this function whenever a packet sent from the server arrives at the client-side.
void clientTimerInterrupt(void)
int clientCanSendMorePkt(void)
All of the server functions are to be defined in the server.c file. Those functions are:
void serverInit(void)
The simulation will call this function only once, before any of your other server-side routines are called. It can be used to do any initialization you think is needed.
void serverEnd(void)
The simulation will call this function only once, just before it
ends. This function can be used to clean-up any state that you
have, for instance if you are using a file to hold debugging
information then you might open the file in
serverInit()
and close it here.
void serverInput(packet_t pkt)
pkt
is a (possibly corrupt) packet that was
sent by the client-side.
The simulated operating system will call this function whenever a
packet sent from the client arrives at the server-side. (The
client sends the packet by calling client_output()
function which tells the simulated operating system to make
packets using its sendToNWSlayer()
function.)
void serverOutput(message_t msg)
msg
is a message containing data to be sent
to the client-side of the connection.
void serverTimerInterrupt(void)
The simulation will call this function when the receiving-side's timer expires (and generates a timer interrupt).
This function is only needed for bidirectional connections (where data, not only acknowledgments, can be sent from the server to the client).
int serverCanSendMorePkt(void)
The simulation will call this function before trying to send data
from the server's application layer to the client. If
serverCanSendMorePkt()
returns a nonzero (true) value
then the oldest unsent packet will be sent to the client,
otherwise the newest packet will be put in a buffer that will be
checked the next time it is possible to send data to the client.
This function is only needed for bidirectional connections (where data, not only acknowledgments, can be sent from the server to the client).
Make sure you read the advice in the overview webpage.
The code that is provided for you is described in the KRnet
webpage.