Standard network method

B

Bonj

Hi
I'd like a way of communicating over a network that doesn't rely on
vendor-specific libraries, preferably that will work on both windows and
linux (the ideal solution would be one that compiles on windows and linux,
but the absolute ideal one would be one that also enables windows to
communicate *with* linux in realtime, but that's a pipe dream as yet...)
Nothing too fancy, the amounts of data won't be great. Just open a
connection on a specific port, send some data down it, close. And receive
from the other end.

i.e. is there a standard library function for it...? I'm thinking along the
lines of fopen(), fread(), ..... , is there an f_tcp() ?

Can be either in C or C++.
 
F

Flash Gordon

Bonj said:
Hi
I'd like a way of communicating over a network that doesn't rely on
vendor-specific libraries,

Then you have a problem.
preferably that will work on both windows and
linux (the ideal solution would be one that compiles on windows and linux,
but the absolute ideal one would be one that also enables windows to
communicate *with* linux in realtime, but that's a pipe dream as yet...)
Nothing too fancy, the amounts of data won't be great. Just open a
connection on a specific port, send some data down it, close. And receive
from the other end.

i.e. is there a standard library function for it...? I'm thinking along the
lines of fopen(), fread(), ..... , is there an f_tcp() ?

Can be either in C or C++.

Nothing like that exists in C. You either need to find a third party
library ported to all the systems you are interested in or write your own.

<OT>
There is a lot of commonality between Windows and *nix, since MS based
their TCP/IP library on BSD Sockets. So writing some thin wrappers is
not that difficult. However, how you do networking is not on topic here,
so ask for details in networking and/or system specific groups.
</OT>

Any C++ answers are off topic in comp.lang.c, so please take it off if
posting a C++ answer.
 
D

Dave O'Hearn

Bonj said:
i.e. is there a standard library function for it...? I'm thinking along
the lines of fopen(), fread(), ..... , is there an f_tcp() ?

Can be either in C or C++.

There is no standard library support for sockets in either C or C++.
Boost does not support sockets yet either.

There are some sockets libraries that claim to be portable to many
platforms, but they are not standard.
 
E

Emmanuel Delahaye

Bonj wrote on 31/12/04 :
I'd like a way of communicating over a network that doesn't rely on

You are completely off-topic ont both newsgroups.
vendor-specific libraries,

Write your own.
preferably that will work on both windows and
linux (the ideal solution would be one that compiles on windows and linux,

BSD Sockets and Winsock2 are very similar.
but the absolute ideal one would be one that also enables windows to
communicate *with* linux in realtime, but that's a pipe dream as yet...)

There is no reason for a network (IP, for example) not to support
mac+linux+windows or anyelse servers/clients... Zillions of working
solutions are running around the world probably for a 10th of years...
Nothing too fancy, the amounts of data won't be great. Just open a connection
on a specific port, send some data down it, close. And receive from the other
end.

i.e. is there a standard library function for it...? I'm thinking along the
lines of fopen(), fread(), ..... , is there an f_tcp() ?

No. I think there is a kind of a portable wrapper for networking, but I
can't recall the name. Search the net. Google is your friend.

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++
 
K

kan Pu

I am not sure what you mean. But a TCP/IP protocol can meet your
requirement. And by the way, I think a open source library "ACE" ( Adaptive
communication envirement), which can be found in www.cs.wustl.edu/~schmidt/
, can be used directly.
 
B

Bonj

Emmanuel Delahaye said:
Bonj wrote on 31/12/04 :

You are completely off-topic ont both newsgroups.

So what's the correct newsgroup to post requesting something in C, that
works on windows and linux then?
Write your own.

Where do I start?
 
G

Gernot Frisch

Bonj said:
Hi
I'd like a way of communicating over a network that doesn't rely on
vendor-specific libraries, preferably that will work on both windows
and linux (the ideal solution would be one that compiles on windows
and linux, but the absolute ideal one would be one that also enables
windows to communicate *with* linux in realtime, but that's a pipe
dream as yet...)
Nothing too fancy, the amounts of data won't be great. Just open a
connection on a specific port, send some data down it, close. And
receive from the other end.

i.e. is there a standard library function for it...? I'm thinking
along the lines of fopen(), fread(), ..... , is there an f_tcp() ?

Can be either in C or C++.

You can download the source code for HawkNL - a cross platform
networking library - based on socks:
http://www.hawksoft.com/hawknl/
I think it's very good, though it's not maintained much anymore I
think.

also, from Alex Vinokur:
C++ Stram Compatible TCP/IP Sockets:
http://sourceforge.net/projects/cpp-sockets/
http://alexvn.freeservers.com/s1/sock.html

HTH,
Gernot
 
I

infobahn

Bonj said:
So what's the correct newsgroup to post requesting something in C, that
works on windows and linux then?

comp.lang.c is the right place to ask questions about portable C
programming. Unfortunately, network programming can't be done in
a way that is sufficiently portable to justify its discussion in
comp.lang.c. Nevertheless, your second question (below) is
topical, in my opinion, so I'll try to answer it.
Where do I start?

Begin by learning how to write networking programs in Linux,
if you don't already know how to do this.

Continue by learning how to write networking programs in
Windows, if you don't already know how to do this.

Finally, abstract the non-portable parts of your programs
into a library, in such a way that you can keep your
application portable. Think of your library as a layer
between your application and the OS-specific aspects
of networking.

For example, under Windows, you need to start the
networking interface using an OS-specific call. Under
Linux, you don't. So you could write a routine
something like this:

/* start_networking() - Windows version */
int start_networking(P p)
{
/* insert Windows networking startup code here */

return 0 if it worked, or a non-zero value otherwise.
}

/* start_networking() - Linux version */
int start_networking(P p)
{
return 0;
}

In your .lib, you'll use the first version. In
your .a or .so, you'll use the second. In both
cases, your application code will look something
like this:

int got_a_network = start_networking(params);
if(got_a_network)
{
do stuff here
}

C++ fans might have a different way of doing
this, but this way will work in both languages.

The point is that, whilst the body of the
library routines will differ across platforms,
the interface stays the same, which means that
your application code itself need not change.

It's not trivial, but it's not rocket science either.
 
I

infobahn

Apologies for following up to my own article...

int got_a_network = start_networking(params);
if(got_a_network)
{
do stuff here
}

This should read:

int network_error = start_networking(params);
if(network_error == 0)
{
do stuff here
}

Oops.
 

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

Members online

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top