Tried to do a bit of research on this topic but couldnt find much, could you'll provide me with a few pointer and tips?
Developing a custom network protocol
Page 1 of 15 Replies - 950 Views - Last Post: 10 June 2012 - 12:54 AM
Replies To: Developing a custom network protocol
#2
Re: Developing a custom network protocol
Posted 21 May 2012 - 07:07 AM
Would you provide everyone more detail on what you want to do and what you have looked into?
#3
Re: Developing a custom network protocol
Posted 23 May 2012 - 12:14 AM
A low level protocol? High level?
Use UDP and build your own hand shaking, acking, verifying etc.
Use UDP and build your own hand shaking, acking, verifying etc.
This post has been edited by stackoverflow: 23 May 2012 - 12:14 AM
#4
Re: Developing a custom network protocol
Posted 09 June 2012 - 02:20 AM
I can't say this is the best way to do this or even its efficient but it works for me.
If you use TCP, you can create structures fill them with data and then send the structure. For example
This will send the full data as one long value to the server the server recv the packet back into a PACKET type. This method works very well for me so I use it all the time.
Another way you can do it is plain text packets, look at the FTP or HTTP protocol. You can also construct the plaintext packet such as
For UDP you use this same method but will also have to include packet verification, so that you know that you got the whole thing.
If anyone else has a better way of doing this, please share because I would love to know.
If you use TCP, you can create structures fill them with data and then send the structure. For example
struct PACKET
{
byte sig; // The id that this is a packet from your protocol
u_long packetType; // If this is a request or response packet (optional).
u_long packetID; // A uniqe 32bit ID that identifies this packet.
__int64 timeStamp; // A 64 bit representation of when the packet was sent.
byte data[ 1024 ]; // The data you want to send.
};
// Create a packet.
PACKET pak;
pak.sig = MY_PACKET_SIG;
pak.packetType = PT_REQUEST;
etc..
// Send the packet to the person.
send( sock, pak, sizeof(pak) );
This will send the full data as one long value to the server the server recv the packet back into a PACKET type. This method works very well for me so I use it all the time.
Another way you can do it is plain text packets, look at the FTP or HTTP protocol. You can also construct the plaintext packet such as
std::string myPak = "PAK_SIG;PAK_TYPE;PAK_ID;PAK_TS;RAW_DATA"; send( myPak );
For UDP you use this same method but will also have to include packet verification, so that you know that you got the whole thing.
If anyone else has a better way of doing this, please share because I would love to know.
#5
Re: Developing a custom network protocol
Posted 09 June 2012 - 06:27 AM
I do something similar but with two more fields
saying this would be packet 14 of 250 for example.
Some of my data are quite large and have to be broken down and reassembled.
This way if one packet is lost in transmission the receiver then requests the missing packet specifically.
- packetNumber
- totalPackets
saying this would be packet 14 of 250 for example.
Some of my data are quite large and have to be broken down and reassembled.
This way if one packet is lost in transmission the receiver then requests the missing packet specifically.
#6
Re: Developing a custom network protocol
Posted 10 June 2012 - 12:54 AM
tlhIn`toq, on 09 June 2012 - 06:27 AM, said:
I do something similar but with two more fields
saying this would be packet 14 of 250 for example.
Some of my data are quite large and have to be broken down and reassembled.
This way if one packet is lost in transmission the receiver then requests the missing packet specifically.
- packetNumber
- totalPackets
saying this would be packet 14 of 250 for example.
Some of my data are quite large and have to be broken down and reassembled.
This way if one packet is lost in transmission the receiver then requests the missing packet specifically.
Thats def a good idea and so simple. Great for large amounts of data or UDP packets. I am gonna have to remember that next time.
Page 1 of 1
|
|

New Topic/Question
Reply


MultiQuote








|