Re: Standard network method
Bonj wrote:[color=blue]
>
> "Emmanuel Delahaye" <emdel@YOURBRAn oos.fr> wrote in message
> news:mn.fc9e7d4 c74d67530.15512 @YOURBRAnoos.fr ...[color=green]
> > Bonj wrote on 31/12/04 :[color=darkred]
> >> I'd like a way of communicating over a network that doesn't rely on[/color]
> >
> > You are completely off-topic ont both newsgroups.[/color]
>
> So what's the correct newsgroup to post requesting something in C, that
> works on windows and linux then?[/color]
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.
[color=blue]
>[color=green]
> > Write your own.[/color]
>
> Where do I start?[/color]
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_networkin g() - Windows version */
int start_networkin g(P p)
{
/* insert Windows networking startup code here */
return 0 if it worked, or a non-zero value otherwise.
}
/* start_networkin g() - Linux version */
int start_networkin g(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_networkin g(params);
if(got_a_networ k)
{
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.
Bonj wrote:[color=blue]
>
> "Emmanuel Delahaye" <emdel@YOURBRAn oos.fr> wrote in message
> news:mn.fc9e7d4 c74d67530.15512 @YOURBRAnoos.fr ...[color=green]
> > Bonj wrote on 31/12/04 :[color=darkred]
> >> I'd like a way of communicating over a network that doesn't rely on[/color]
> >
> > You are completely off-topic ont both newsgroups.[/color]
>
> So what's the correct newsgroup to post requesting something in C, that
> works on windows and linux then?[/color]
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.
[color=blue]
>[color=green]
> > Write your own.[/color]
>
> Where do I start?[/color]
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_networkin g() - Windows version */
int start_networkin g(P p)
{
/* insert Windows networking startup code here */
return 0 if it worked, or a non-zero value otherwise.
}
/* start_networkin g() - Linux version */
int start_networkin g(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_networkin g(params);
if(got_a_networ k)
{
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.
Comment