Build TCP Protocol using C#

With few steps, C# code for your TCP protocol will be ready, the structure of any TCP protocol generated by .Net Protocol Builder can be described in the following diagram, please note that the generated code is Multi-threaded server and non blocking client connection.

One or more Request Packets

The answer can be

One or more Response Packets

One or more Two-Way Packets

One or moreTwo-Way Packets

The answer can be

One or more Response Packets

One or more Two-Way Packets

One Event

The answer can be

NO answer

Packets are chunk of data containing your own Fields, Packet ID, Packet Type, Packet Start, Packet End, and some constraints on length, all of these factors are generated automatically by .Net protocol Builder, at the end you will deal with packets as objects with some member variables, these variables are your Fields. Fields can be of the type: string, DateTime, double, all kinds of integers, and an array of bytes (byte[]), keep reading to know what is the difference between all packet types.

Request Packets:

Request packets are sent from client to server only; we can send one or more request packets to the server to get one or more response packets. Requests can be accompanied by two way packets.

Response Packets:

Response packets are sent from server to client only; we can send one or more response packets to the client as a response for its request(s). Responses can be accompanied by two way packets.

Two Way Packets:

Two Way Packets are sent from server to client or from client to server; we can send one or more two way packets from both sides. two way packets can be accompanied by responses and requests.

Event Packets:

Event Packets are sent from client to server only; we can send only one Event packet at a time, they can be used to inform the server about an event occurring at the client side. Event packet is received by the server silently, i.e. there will be no response from the server to the client.

·Select the Protocol node then Set the Protocol Name Use short name for your protocol, keep all other settings with default values.

·To add a packet select the suitable packet type under the protocol node, right click the node and click add packet (you may change its name).

·To add a Field right click on the packet node and click Add Field (you may change its name and type).

Generating Protocol Code and its Documentation

After adding all packets and fields, you can generate the C# code by selecting Generate Code from the tools menu or use the Keyboard shortcut Ctrl+G, the program will prompt you to select the path of the working directory if you have not done so, your protocol files will be saved inside a new folder called Protocol prefixed with your protocol name. Congratulations!! Your protocol code is ready to be added to your own project. Try it Now

Protocol documentation in .docx format can be generated by selecting “Generate Protocol Documentation” from the tools menu or by selecting Ctrl+D, this will generate new file called “Protocol Documentation.docx” prefixed with your protocol name, this file will be saved in the protocol folder in the current working directory. Note that Word 2007 is required to generate this type of documentation.

The documentation in .txt format will be generated automatically each time you generate the protocol code, so this type of documentation is consistent with your protocol all the time, where you have to make sure to generate the .docx documentation each time you change the design of your protocol.

Saving your protocol

Anytime you can save your protocol design by selecting Save from the File menu and Open it later by selecting Open from the File Menu. If you have designed your protocol using the Trial version the standard edition is able to open your file.