Standard network method

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • infobahn

    #16
    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.

    Comment

    • infobahn

      #17
      Re: Standard network method

      Apologies for following up to my own article...

      infobahn wrote:[color=blue]
      >[/color]

      <snip>
      [color=blue]
      > int got_a_network = start_networkin g(params);
      > if(got_a_networ k)
      > {
      > do stuff here
      > }[/color]

      This should read:

      int network_error = start_networkin g(params);
      if(network_erro r == 0)
      {
      do stuff here
      }

      Oops.

      Comment

      • Mark McIntyre

        #18
        Re: Standard network method

        On Mon, 3 Jan 2005 09:11:28 -0000, in comp.lang.c , "Bonj" <a@b.com> wrote:

        (someone said)[color=blue][color=green]
        >> Anyway, the C language has no support for any sort of networking
        >> whatsoever, TCP-sockets or otherwise. Actually C predates TCP by quite
        >> many years.[/color]
        >
        >I'm not bothered about whether it's actually defined as part of the C
        >standard. As long as it's "standard enough" to work on windows and linux.[/color]

        Then you need to ask in the right group - comp.unix.progr amming tends to
        handle sockets questions I think, and with some care the answers can be
        applied to other OSen too.

        --
        Mark McIntyre
        CLC FAQ <http://www.eskimo.com/~scs/C-faq/top.html>
        CLC readme: <http://www.ungerhu.com/jxh/clc.welcome.txt >

        ----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
        http://www.newsfeeds.com The #1 Newsgroup Service in the World! 120,000+ Newsgroups
        ----= East and West-Coast Server Farms - Total Privacy via Encryption =----

        Comment

        Working...