Thread: Which Sockets Library

  1. #1
    Chad Johnson
    Join Date
    May 2004
    Posts
    154

    Question Which Sockets Library

    I'm learning sockets programming now, and I've done everything in Java so far for simplicity's sake. I want to actually make a real program now using C++, so I need to select a sockets library.

    I have been using wxWidgets for my GUI. Should I just use the socket functions included in wxWidgets? Apparently it wraps the socket functions that the OS/Environment uses.

    Or, is there a better library? Is there one that will work on Windows, Linux, Mac OS[X], OpenBSD, etc....?

    I don't want to have to rewrite my programs from scratch for each OS. If I don't use wxWidgets, what I usually do is write the libraries and use them in each OS version, then I write the GUI for that OS and incorporate those libraries (and I basically JUST have to write a GUI).

    What library should I use?


    Is this one any good? --> http://www.libsockets.net/
    How about the BSD Socket library (is there a port for Windows?)
    Last edited by ChadJohnson; 09-15-2004 at 10:47 AM.

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    I would suggest using raw sockets. BSD on *nix machines, and winsock on windows. The differences between the two are very small, so porting between platforms takes very little time.

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    I would say use the wxWidgets library first - if it seems to perform poorly you can try something else.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by ChadJohnson
    I've done everything in Java so far for simplicity's sake. I want to actually make a real program now
    *sigh*

    As for the question, aren't the socket functions used in most C programs fairly standard?
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

  5. #5
    Chad Johnson
    Join Date
    May 2004
    Posts
    154
    Is there a standard C library for sockets? I haven't really looked...

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    the C standard doesn't specify any socket/networking specification per se, but the BSD socket library has become the de facto standard for socket programming. suprisingly enough (not!) Microsoft implemented their own version that made some minor modifications plus added quite a few extensions. the MS header you'll need is 'winsock.h', for Unix/Linux I think it's 'sys/socket.h'. you'll also need to direct your linker to the actual code of the library, and that will be completely dependant on the compiler (ie: for Bloodshed-Dev it's in 'libwsock32.a'). there are numerous socket tutorials on the net in C/C++ (including Beej's guide) that will help get you started, too. the bottom line is: as long as you stick to the BSD-style functions (and avoid the MS ones), you'll be almost 100% portable.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  7. #7
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>the MS header you'll need is 'winsock.h'
    Actually, I think it's 'winsock2.h' unless you're programming for Windows 3.1...
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  8. #8
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    its only winsock2.h if you need winsock 2 functions... good old 1.1 still works fine under NT5+ and iirc most of the winsock2 stuff doesnt fit well with bsd sockets anyway
    hello, internet!

  9. #9
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Posts
    2,879
    >>most of the winsock2 stuff doesnt fit well with bsd sockets anyway
    True, I suppose that would be a problem for the OP. But it contains all the 1.1 features anyways, and allows you to use winsock 2 functions if you so desire.
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 05:00 PM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 06:04 AM
  3. Library for pool, sockets, threads
    By Mortissus in forum C++ Programming
    Replies: 13
    Last Post: 07-14-2007, 07:41 AM
  4. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 04:52 AM
  5. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 07:55 AM