Transitioning from serial communications to tcp/ip.

F

Frank Rizzo

Hello, I am having a bit of trouble understanding how tcp/ip works. As
a point of reference, with a serial port you essentially get byte by
byte in the same order that it was sent out.

With TCP/IP, because it may route individual packets via different
paths, does a possibility exist that I will get some packets out of
order? Or is this something that is handled by the tcp/ip stack?

Secondly, how can I send tcp/ip data (i.e. length of data) to guarantee
that when I call do the following:

byte[] Receiving = new byte[100000];
m_Socket.Receive(Receiving, 0, m_Socket.Available, SocketFlags.None);

that I get everything I sent in one shot. So for instance, if the
client sends: "the brown fox jumped over the i can't remember what", I
want to be sure that when the server calls the piece of code above, that
the entire string is in the Receiving array.


Thanks.
 
T

Tom Shelton

Hello, I am having a bit of trouble understanding how tcp/ip works. As
a point of reference, with a serial port you essentially get byte by
byte in the same order that it was sent out.

With TCP/IP, because it may route individual packets via different
paths, does a possibility exist that I will get some packets out of
order? Or is this something that is handled by the tcp/ip stack?

TCP guarentees that you will recieve the packets in the order they were
sent. UDP on the other hand does not.
Secondly, how can I send tcp/ip data (i.e. length of data) to guarantee
that when I call do the following:

byte[] Receiving = new byte[100000];
m_Socket.Receive(Receiving, 0, m_Socket.Available, SocketFlags.None);

that I get everything I sent in one shot. So for instance, if the
client sends: "the brown fox jumped over the i can't remember what", I
want to be sure that when the server calls the piece of code above, that
the entire string is in the Receiving array.

You can't. That's why tcp based protocols generally include some sort
of end of message dilimiter.
 
F

Frank Rizzo

Tom said:
Hello, I am having a bit of trouble understanding how tcp/ip works. As
a point of reference, with a serial port you essentially get byte by
byte in the same order that it was sent out.

With TCP/IP, because it may route individual packets via different
paths, does a possibility exist that I will get some packets out of
order? Or is this something that is handled by the tcp/ip stack?

TCP guarentees that you will recieve the packets in the order they were
sent. UDP on the other hand does not.
Secondly, how can I send tcp/ip data (i.e. length of data) to guarantee
that when I call do the following:

byte[] Receiving = new byte[100000];
m_Socket.Receive(Receiving, 0, m_Socket.Available, SocketFlags.None);

that I get everything I sent in one shot. So for instance, if the
client sends: "the brown fox jumped over the i can't remember what", I
want to be sure that when the server calls the piece of code above, that
the entire string is in the Receiving array.

You can't. That's why tcp based protocols generally include some sort
of end of message dilimiter.

So what you are saying that I'd have to have an intermediate variable to
store & concatenate the incoming data until I see a delimiter?
 
T

Tom Shelton

Tom said:
Hello, I am having a bit of trouble understanding how tcp/ip works. As
a point of reference, with a serial port you essentially get byte by
byte in the same order that it was sent out.

With TCP/IP, because it may route individual packets via different
paths, does a possibility exist that I will get some packets out of
order? Or is this something that is handled by the tcp/ip stack?

TCP guarentees that you will recieve the packets in the order they were
sent. UDP on the other hand does not.
Secondly, how can I send tcp/ip data (i.e. length of data) to guarantee
that when I call do the following:

byte[] Receiving = new byte[100000];
m_Socket.Receive(Receiving, 0, m_Socket.Available, SocketFlags.None);

that I get everything I sent in one shot. So for instance, if the
client sends: "the brown fox jumped over the i can't remember what", I
want to be sure that when the server calls the piece of code above, that
the entire string is in the Receiving array.

You can't. That's why tcp based protocols generally include some sort
of end of message dilimiter.

So what you are saying that I'd have to have an intermediate variable to
store & concatenate the incoming data until I see a delimiter?

Yep... Pretty much. I would look at the async socket examples on MSDN.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Modbus TCP/IP 0
TCP/IP receive question. 1
Getting TCP/IP information. 3
reconnect tcp 3
Asynchronous image transfer over TCP/IP socket 0
How to know Tcp/ip Drop 1
Async TCP Sockets 5
C# and TCP/IP sockets 1

Top