IP socket programming?

Armitage

Banned
Feb 23, 2001
8,086
0
0
Anybody have any good references. Preferably for C/C++ or Python on Unix.

I'm on the hook for a smallish project that will have to receive its data this way and I've never done anything like it before. And the timeline to have it done is pretty tight as well!
Thanks

 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
Get a class library, unless you really want to dive into raw socket programming. I'm not a unix guy, but there must be a couple of dozen C++ socket libs out there.
 
Sep 29, 2004
18,656
67
91
I've done socket programming before. It's honestly worth while learning the first time around. Do it the hard way (no libraries).

The most enjoyable thing I did (and got paid for it) was to wrap scoket code into my own C++ library. When I was done, it was solid!

Those were teh good days ;)

Learn the stack at a minimum, even if you use libraries.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: Markbnj
Get a class library, unless you really want to dive into raw socket programming. I'm not a unix guy, but there must be a couple of dozen C++ socket libs out there.

Yep, that's what I'm hoping to find. I'm to busy, and the timeline is to short to start from scratch.
 

xtknight

Elite Member
Oct 15, 2004
12,974
0
71
No offense but to be honest I don't know how it could be made any simpler. There is connect() and recv(), just about all you need to do a simple receive operation.

Can you describe what you're looking for specifically?
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
Unix sockets are treated just like file descriptors except you call socket(2) to get the fd created and then connect(2) to connect to a remote point. Once it's established you can read(2)/write(2) to your hearts content. There's obviously a lot more to the complete subject, but that's enough to get started. And unlike Windows you have man pages for nearly all the functions you need, run 'man 2 connect' and you'll get the man page for the connect function call.

Also there's a ton of OSS network tools out there that you can inspect the code for, netcat is only ~1600 lines including comments and a lot of #ifdefs for different options. It might be a little scarey to read at first, but it's full of socket examples =)
 

Markbnj

Elite Member <br>Moderator Emeritus
Moderator
Sep 16, 2005
15,682
14
81
www.markbetz.net
No offense but to be honest I don't know how it could be made any simpler. There is connect() and recv(), just about all you need to do a simple receive operation.

Yeah, but most of the complexity (and I am not saying it's overwhelming) is in all the ancillary stuff you have to do before you can call those simple functions. In a well-rounded program you're going to be converting addresses back and forth, dealing with conversions from network to host byte order, doing host lookups, binding sockets to addresses, setting up listening ports, etc. Sure, it is all filling out structures and calling functions, but it can get pretty obtuse in places.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
First you need to figure out how the device acts and what you're expecting to come from it. Will it only connect once per dialup connection? Will it stay connected after the first connection and just keep using that connection? Will it connect every time someone dials up even if another connection is already established?
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: Nothinman
First you need to figure out how the device acts and what you're expecting to come from it. Will it only connect once per dialup connection? Will it stay connected after the first connection and just keep using that connection? Will it connect every time someone dials up even if another connection is already established?

Thanks - good questions. I'll be talking to one of their engineers this. a.m. I'm hoping they have some kind of documentation or reference implementation available.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
If they do give you a reference implementation it'll probably contain 99% of the networking code that you'll need, the difficult part will most likely be handling the data given to you by the device.
 

Armitage

Banned
Feb 23, 2001
8,086
0
0
Originally posted by: Nothinman
If they do give you a reference implementation it'll probably contain 99% of the networking code that you'll need,

That's what I'm hoping!

the difficult part will most likely be handling the data given to you by the device.

Which shouldn't be that difficult. Calling now...