Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Re: TCP Socket Programming (http://www.velocityreviews.com/forums/t746970-re-tcp-socket-programming.html)

Martin Ambuhl 04-18-2011 07:12 AM

Re: TCP Socket Programming
 
On 4/18/2011 2:58 AM, Ajit Teli wrote:
> I am writting a c program to send tcp packet (packet is a string) over socket.
> Please tell me how to form a string which contains NUL char.


Your TCP documentation may tell you that a packet is a string, but it is
not, at least not a string as defined in C. It is a series of values,
probably storable in chars, which is not the same thing.

A string in C is terminated by a char with the value 0, and ASCII NUL is
such a value. Now you might store the values in an array of char.
Every string is an array of char, but not every array of char is a
string. Remember that a string is terminated by a 0-valued char. If
your array has none, then it is not a string. If it has such a char
embedded in data, then the initial string ends there.

To send a sequence of values stored in a char array, the simplest way is
to simply send each of the values until you reach the end of the array.


Martin Ambuhl 04-18-2011 07:50 AM

Re: TCP Socket Programming
 
On 4/18/2011 3:12 AM, Martin Ambuhl wrote:
> On 4/18/2011 2:58 AM, Ajit Teli wrote:
>> I am writting a c program to send tcp packet (packet is a string) over
>> socket.
> > Please tell me how to form a string which contains NUL char.

>
> Your TCP documentation may tell you that a packet is a string, but it is
> not, at least not a string as defined in C. It is a series of values,
> probably storable in chars, which is not the same thing.
>
> A string in C is terminated by a char with the value 0, and ASCII NUL is
> such a value. Now you might store the values in an array of char. Every
> string is an array of char, but not every array of char is a string.
> Remember that a string is terminated by a 0-valued char. If your array
> has none, then it is not a string. If it has such a char embedded in
> data, then the initial string ends there.
>
> To send a sequence of values stored in a char array, the simplest way is
> to simply send each of the values until you reach the end of the array.
>


I should add:

If you are doing TCP/IP programming, you should have a library of
functions which handles packets. Perhaps those are in your sockets
library if not in a separate TCP/IP library. You should have routines
to which you pass the address of the packet and perhaps its length as
well, and that routine should handle all the necessary work for you.


Bill Cunningham 04-22-2011 07:02 PM

Re: TCP Socket Programming
 
Martin Ambuhl wrote:

> I should add:
>
> If you are doing TCP/IP programming, you should have a library of
> functions which handles packets. Perhaps those are in your sockets
> library if not in a separate TCP/IP library. You should have routines
> to which you pass the address of the packet and perhaps its length as
> well, and that routine should handle all the necessary work for you.


This would be done with ntos() and ntol() and such wouldn't it? I have
UNIX network programming and it is a very good book. That is what I've read
so far. Beeg's guide mentioned later in this thread is a very excellent
tutorial too.

Bill




All times are GMT. The time now is 09:48 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.