Server Side Sample Code

To use the generated code in the server side you need to do two steps:

1-Create Listener instance and start it to listen for new client connections.

2-Implement the Answer method in the Answer Class which is generated with the protocol code, this method will describe how you will answer your requests and two-way packets and how you will update the server status depending on the received events from clients, for more information see Help in .Net Protocol Builder.

The next example demonstrates how we initialize a listener and start it, and how we implement the Answer Class for the previous Client Side sample (protocol name is “Mos”).

1-To start a Listener

MyListener = newMosListener();

MyListener.Start();

2-Answer Method Sample implementation

publicMosPacketCollection Answer()

{

// Here you can iterate through Reqs received from the Client,

// and return a new Packet collection as a response for them.

// if you have got an Event, then update the server state as appropriate, and return null.

MosPacketCollection Responses = newMosPacketCollection();

foreach (MosPacket P in Reqs)

{

if (P isMosGetDatePacket)

{

Responses.Add(newMosSetDatePacket(P.SessionID, DateTime.Now));

}

elseif (P isMosGetSettings)

{

// This is to show how to use the generated constructor for one packet.