Register for your free account! | Forgot your password?

You last visited: Today at 16:14

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Packet Receiving...

Discussion on Packet Receiving... within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
badguy4you's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 477
Received Thanks: 178
Packet Receiving...

I read this on the internet
Quote:
The Problem

One of the most common beginner mistakes for people designing protocols for TCP/IP is that they assume that message boundaries are preserved. For example, they assume a single "Send" will result in a single "Receive".

Some TCP/IP documentation is partially to blame. Many people read about how TCP/IP preserves packets - splitting them up when necessary and re-ordering and re-assembling them on the receiving side. This is perfectly true; however, a single "Send" does not send a single packet.

Local machine (loopback) testing confirms this misunderstanding, because usually when client and server are on the same machine they communicate quickly enough that single "sends" do in fact correspond to single "receives". Unfortunately, this is only a coincidence.

This problem usually manifests itself when attempting to deploy a solution to the Internet (increasing latency between client and server) or when trying to send larger amounts of data (requiring fragmentation). Unfortunately, at this point, the project is usually in its final stages, and sometimes the application protocol has even been published!

True story: I once worked for a company that developed custom client/server software. The original communications code had made this common mistake. However, they were all on dedicated networks with high-end hardware, so the underlying problem only happened very rarely. When it did, the operators would just chalk it up to "that buggy Windows OS" or "another network glitch" and reboot. One of my tasks at this company was to change the communication to include a lot more information; of course, this caused the problem to manifest regularly, and the entire application protocol had to be changed to fix it. The truly amazing thing is that this software had been used in countless 24x7 automation systems for 20 years; it was fundamentally broken and no one noticed.
So my problem is, I am developing a client server application, and i wonder how to prevent packet receiving problems [such the one above]

Here is the way i send a message to the server from my simple client

[CLIENT]
Code:
        TcpClient Client = new TcpClient();
        IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 13000);

        private void btnSend_Click(object sender, EventArgs e)
        {
            NetworkStream clientStream = Client.GetStream();

            ASCIIEncoding encoder = new ASCIIEncoding();
            byte[] buffer = encoder.GetBytes(textMessage.Text);

            clientStream.Write(buffer, 0, buffer.Length);
            clientStream.Flush();
        }
Assuming that i want to send login data so i decided that my message will look like this
Code:
string msg = "1001:UN=badguy4you&&PW=5001"; //1001 is the id
[SERVER]
Code:
        private void OnReceivePacket(byte[] buffer, IE Client)
        {
            try
            {
                int ID;
                string V = Encoding.ASCII.GetString(buffer).Split(':')[0];
                int.TryParse(V, out ID);

                switch (ID)
                {
                    case 1001:
                        Append("Login Packet Received");
                        break;

                    case 1002:
                        //Other IDs
                        break;

                    default:
                        break;
                }
            }
            catch { }         
        }
So that is i am doing\handling the sent and received messages between my Client and Server. Can you tell me am i doing this in the right way or there is something i am doing wrong ?!

Also What is the difference between Encoding.ASCII and Encoding.UTF8 ?
badguy4you is offline  
Old 09/09/2012, 03:23   #2
 
Danial Eugen's Avatar
 
elite*gold: 0
Join Date: Sep 2012
Posts: 171
Received Thanks: 68
There is no problem with the way you send receive the messages as i see in your code

And about the Encoding use UTF8 if you are going to use unicode characters
Danial Eugen is offline  
Old 09/09/2012, 03:57   #3
 
EpicNinjaKick's Avatar
 
elite*gold: 0
Join Date: Sep 2012
Posts: 69
Received Thanks: 7
No point in commenting - hes banned.
UTF - 8 Unicode
UTF general ci
EpicNinjaKick is offline  
Old 09/17/2012, 01:17   #4
 
badguy4you's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 477
Received Thanks: 178
Quote:
Originally Posted by EpicNinjaKick View Post
No point in commenting - hes banned.
UTF - 8 Unicode
UTF general ci
So i am not banned [it was 2 weeks due to 3 infractions] and i still need help
badguy4you is offline  
Old 09/17/2012, 01:32   #5
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Take a look at the socket tutorial I've posted (Link in my signature).

Also maybe take a look at the source of Buu (My packet analyzer / proxy).
I don't have a username is offline  
Thanks
2 Users
Old 09/18/2012, 19:52   #6
 
badguy4you's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 477
Received Thanks: 178
Quote:
Originally Posted by I don't have a username View Post
Take a look at the socket tutorial I've posted (Link in my signature).

Also maybe take a look at the source of Buu (My packet analyzer / proxy).
So is the way i am sending and receiving the message at my topic wrong ? also i wonder when you mention a packet it is going to be something like

A0 E7 T3 E4 E6 ....

When i mention a packet i think it is

Encoding.ASCII.GetBytes("ID:MESSAGE");
THEN
Encoding.ASCII.GetString(buffer).Spilit(':')[0]; //ID
Encoding.ASCII.GetString(buffer).Spilit(':')[1]; //Message

i am totally confused how could i send data from my client and then determine which thing i have received on the server

Like
Code:
if(packet.id == 5001) //Do some stuff;
badguy4you is offline  
Old 09/18/2012, 20:36   #7
 
elite*gold: 0
Join Date: Dec 2011
Posts: 1,537
Received Thanks: 785
Quote:
Originally Posted by badguy4you View Post
So is the way i am sending and receiving the message at my topic wrong ? also i wonder when you mention a packet it is going to be something like

A0 E7 T3 E4 E6 ....

When i mention a packet i think it is

Encoding.ASCII.GetBytes("ID:MESSAGE");
THEN
Encoding.ASCII.GetString(buffer).Spilit(':')[0]; //ID
Encoding.ASCII.GetString(buffer).Spilit(':')[1]; //Message

i am totally confused how could i send data from my client and then determine which thing i have received on the server

Like
Code:
if(packet.id == 5001) //Do some stuff;
Quote:
Originally Posted by badguy4you
Quote:
Originally Posted by I don't have a username View Post
Take a look at the socket tutorial I've posted (Link in my signature).

Also maybe take a look at the source of Buu (My packet analyzer / proxy).
So is the way i am sending and receiving the message at my topic wrong ? also i wonder when you mention a packet is is going to be something like

A0 E7 T3 E4 E6 ....

When i mention a packet i think it is

Encoding.ASCII.GetString(buffer);

i am totally confused how could i send data from my client and then determine which thing i have received on the server

Like
Code:
if(packet.id == 5001) //Do some staff;
Please i need your help with that because i completely lost

I don't really get it... The first thing:
Code:
A0 E7 T3 E4 E6
That's a packet dump. Each value you see there is the bytes in your packet, but converted to hex.

This:
Code:
Encoding.ASCII.GetString(buffer);
is converting the bytes to a string. It's equal to:
Code:
string s = "";
foreach (byte b in buffer)
s += (char)b;
^ StringBuilder would be better here thought, but this is just for you to understand.

To get this:
Code:
if(packet.id == 5001)
You'd have to read the actual values in the packet ex. for conquer the id is an ushort.
An ushort is 2 bytes.

The first 4 bytes is 2 ushorts which is size and id in CO.

That would make it like this:
Code:
size = buffer[0] & buffer[1]
id = buffer[2] & buffer[3]
You'd have to combine those two bytes to a single value. I'd recommend pointers for this.

Ex.
Code:
public ushort ReadUInt16(int offset)
{
return (*(ushort*)(bufferPointer + offset));
}
Now the above code won't work because you have to specify a pointer.

Code:
public byte* bufferPointer
{
get
{
fixed (byte* Ptr = buffer)
return Ptr;
}
}
Notice this rquires "allow unsafe coding".
Go to properties -> build and then check the checkbox.

Uhmm... I figure you already have a packetwriter/packetreader, so the above is just to get an understanding.
I don't have a username is offline  
Old 09/18/2012, 21:08   #8
 
badguy4you's Avatar
 
elite*gold: 0
Join Date: May 2008
Posts: 477
Received Thanks: 178
Quote:
Originally Posted by I don't have a username View Post
Uhmm... I figure you already have a packetwriter/packetreader, so the above is just to get an understanding.
No i don't have, i am completely clueless about the packet thing
badguy4you is offline  
Reply


Similar Threads Similar Threads
Data Receiving Error
09/05/2012 - Shaiya Private Server - 1 Replies
Any know how to fix, it starts after 3 hours the server is online, When you try to log in server get this error, in start was not so after a while it started this problem!
Receiving packets
09/24/2011 - CO2 Private Server - 9 Replies
When I receive a packet I do something like this: public static void NewPacket(SocketClient Client, byte Packet) { if (Kernel.SafePacket(Client, Packet)) { //Handle } }
[Question]about receiving from the Client
06/03/2011 - CO2 Private Server - 12 Replies
well am working on a (C++)Socket for the newest client and i have noticed something that i should wait like 1-2 secs after sending the SeedPacket to the Client in order to receive anydata . is that true? , or my receiving method bugged somehow!!!
Receiving quest reward with DC
12/13/2007 - Cabal Online - 8 Replies
Hi i have an idea how to receive the quest rewards with DC. But i don't know exactly is it working. 1. You do a quest, lets say you must collect 5 quest items 2. Go to an NPC with all items. 3. When you are finishig the quest, dissconect your PC from the internet. 4. When you relog in you will see that you have 4/5 quest items and you received the quest reward. I had that few times. Can someone check it? If it does work it's a good possybility to earn a lot of alz without killing too...



All times are GMT +2. The time now is 16:14.


Powered by vBulletin®
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2024 elitepvpers All Rights Reserved.