Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

c++ sockets

Options
  • 19-10-2008 3:23am
    #1
    Closed Accounts Posts: 66 ✭✭


    i've searched around the net and i cant seem to find a tutorial/example that works. i've found a few in compiled versions but the source seems to give me issues. the only compiled version that seems to show it actually works when its run is
    http://members.aol.com/dsc30574/sockets/index.html
    but oddly when i load it into devcpp (windows vista) and try compile it it comes up straight away with compiled complete but i get no exe... tried multiple work arounds but no luck infact i copied and pasted the text into a new source file and typed in gibberish half way through (not commented out) and it still said compiled fine.

    I've had other c and c ++ programs compile and run fine for me that werent socket.

    its been hinted along the way that it might be to do with linking .lib files and there was one that compiled fine and listened on port 8888 but as soon as i attempted to connect it just closed down and i cant decipher the code.
    i added in -lwsock32 to parameters and linkers which ive attempted and numerous of all the other onesbut no luck.

    I'm hoping i've done something incredably stupid and trivial.
    To sum up: why arent any of these working,how do i get them to work, and if all the examples are just for unix or old and outdated/not working does anyone have a simple example that compiles that i could examine?
    Thank you


Comments

  • Registered Users Posts: 2,534 ✭✭✭FruitLover


    I'd say the vast majority of C++ sockets tuts will be aimed at unix programmers. Do a search for winsock programming, and you should find what you need (tbh, most of it is the same).


  • Registered Users Posts: 37,485 ✭✭✭✭Khannie


    The unix sockets examples should work on windows with cygwin methinks. Never did any sockets programming on windows, but it's straightforward on unix / linux.


  • Registered Users Posts: 2,082 ✭✭✭Tobias Greeshman


    It's almost equally straightforward on windows.

    You just need to learn the API's and you're away with it.
    #include <winsock.h>
    // ...
    
    // init Winsock, check version is correct, etc
    //
    WSAStartup() 
    
    SOCKET s;
    
    // Now you can use socket, open, connect, listen, send, recv, etc
    // They all pretty much mirror the berkely/unix network api's.
    
    // Close winsock
    //
    WSAShutdown();
    


Advertisement