https://github.com/AustinGarrettRichards/TCP-System
Just rewrote it, Looking for feedback on the socket system and the way I did the events and packets. Feel free to use/modify as well.
Thanks!
https://github.com/AustinGarrettRichards/TCP-System
Just rewrote it, Looking for feedback on the socket system and the way I did the events and packets. Feel free to use/modify as well.
Thanks!
Looks simple and to the point. How are packets created?
It has been modified and completed since last post.
Packets are created quite simply.
First you would create the packet class itself, and set the data. Currently it only supports integers, floats, shorts, strings, and longs. However, you can have it support arrays of these objects in the packet class when reading and writing the data. Simply send the length of the array and then loop through the contents, then in the receive function take in an int, then loop and take in a number of ints based on the received array size. It can also be modified to support other data types, and byte arrays quite easily.
Here is the code to create an instance of a packet and send it. Any class that subscribes to packet 1 (Code example in ExampleManager) will receive the packet.
//Create packet instance
ExamplePacket_1 packet = new ExamplePacket_1();
//Assign packet data
packet.index = 243756;
packet.index2 = 1002;
//Send packet
connectionManager.sendPacketToServer(packet);
Yeah I think supporting byte arrays is important, as it is a nice catch all for sending any data type. In my network solution I send most data as custom C# classes which I serialize to byte arrays. The network solution gets the byte array to the other end and I deserialize it back to the original class instance for use with whatever I needed it for.
I also created methods for serializing strings, Vector3ās, and Quaternions, to and from byte arrays. BitConverter can handle all the basic types.
Definitely. Iām going to add support for it now :).