Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Re: TCP Socket Programming

Reply
Thread Tools

Re: TCP Socket Programming

 
 
Martin Ambuhl
Guest
Posts: n/a
 
      04-18-2011
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.

 
Reply With Quote
 
 
 
 
Martin Ambuhl
Guest
Posts: n/a
 
      04-18-2011
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.

 
Reply With Quote
 
 
 
 
Bill Cunningham
Guest
Posts: n/a
 
      04-22-2011
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
socket.unbind or socket.unlisten? - socket.error: (48, 'Addressalready in use') Laszlo Nagy Python 1 01-27-2009 05:05 PM
TCP Socket Programming Mac Man Ruby 1 09-06-2008 06:50 PM
send tcp raw socket (bogus tcp header length) Tiger C Programming 5 05-01-2006 05:53 AM
Re: tcp socket programming Mohammed Smadi Python 0 10-04-2005 06:13 PM
tcp socket programming Mohammed Smadi Python 1 10-04-2005 05:31 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57