5 Replies - 1500 Views - Last Post: 10 June 2012 - 12:54 AM

#1 Handler  Icon User is offline

  • D.I.C Head

Reputation: 15
  • View blog
  • Posts: 199
  • Joined: 01-April 10

Developing a custom network protocol

Posted 20 May 2012 - 11:39 PM

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?
Is This A Good Question/Topic? 0
  • +

Replies To: Developing a custom network protocol

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 8937
  • View blog
  • Posts: 33,473
  • Joined: 12-June 08

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?
Was This Post Helpful? 0
  • +
  • -

#3 stackoverflow  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 164
  • View blog
  • Posts: 545
  • Joined: 06-July 11

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.

This post has been edited by stackoverflow: 23 May 2012 - 12:14 AM

Was This Post Helpful? 0
  • +
  • -

#4 Cenron  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 13
  • Joined: 23-May 12

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

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.
Was This Post Helpful? 1
  • +
  • -

#5 tlhIn`toq  Icon User is offline

  • Please show what you have already tried when asking a question.
  • member icon

Reputation: 5436
  • View blog
  • Posts: 11,656
  • Joined: 02-June 10

Re: Developing a custom network protocol

Posted 09 June 2012 - 06:27 AM

I do something similar but with two more fields
  • 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.
Was This Post Helpful? 0
  • +
  • -

#6 Cenron  Icon User is offline

  • New D.I.C Head

Reputation: 6
  • View blog
  • Posts: 13
  • Joined: 23-May 12

Re: Developing a custom network protocol

Posted 10 June 2012 - 12:54 AM

View PosttlhIn`toq, on 09 June 2012 - 06:27 AM, said:

I do something similar but with two more fields
  • 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.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1