Results 1 to 14 of 14

Thread: windows sockets

  1. #1
    Guest

    Question

    how do I use winsock in C++?

    I would search my lib directory for something, but I am at school right now, and all they have is Turbo C++ 4.5




    Thanks,
    Dennis

  2. #2
    Guest
    Ok,
    I found winsock1.h and winsock2.h

    which one should I use for simple TCP/IP communication(just for chat programs and stuff)?


    and if you know that.. what functions should i use, and how should I use them?

    and one more thing, do I need to add anything else to my project to make it work??


    Thanks,
    Dennis Wrenn

    PS: using visual C++ 6 enterprise

  3. #3
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Version 2 is definitely the one to go for. Although, make sure you link with winsock.lib.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Whoops...no it isn't!!!!!

    Header: Declared in Winsock2.h.
    Library: Use Ws2_32.lib.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5
    Guest
    how do I add a lib file to my project?(VC++6)


  6. #6
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Project Settings, then the Link tab. Then add it to the text box for "Object/Library Modules".
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  7. #7
    Guest
    cool,

    thanks,

    what functions and stuff do I use.. to connect... to recieve data... etc.?

  8. #8
    Guest
    Does anyone have any WinSock tutorials?

  9. #9
    Guest
    I don't... but I am looking too....

    I asked someone.. and they said to use these functions(easier then the WSA--- ones)

    Socket Functions
    The Windows Sockets specification includes all the following Berkeley-style socket routines that were part of the Windows Sockets 1.1 API.
    Code:
    Routine Meaning 
    accept1 An incoming connection is acknowledged and associated with an immediately created socket. The original socket is returned to the listening state. 
    
    bind Assigns a local name to an unnamed socket. 
    
    closesocket Removes a socket from the per-process object reference table. Only blocks if SO_LINGER is set with a nonzero time-out on a blocking socket. 
    
    connect1 Initiates a connection on the specified socket. 
    
    getpeername Retrieves the name of the peer connected to the specified socket. 
    
    getsockname Retrieves the local address to which the specified socket is bound. 
    
    getsockopt Retrieves options associated with the specified socket. 
    
    htonl2 Converts a 32-bit quantity from host-byte order to network-byte order. 
    
    htons2 Converts a 16-bit quantity from host-byte order to network-byte order. 
    
    inet_addr2 Converts a character string representing a number in the Internet standard ".'' notation to an Internet address value. 
    
    inet_ntoa2 Converts an Internet address value to an ASCII string in ".'' notation that is, "a.b.c.d''. 
    
    ioctlsocket Provides control for sockets. 
    listen Listens for incoming connections on a specified socket. 
    
    ntohl2 Converts a 32-bit quantity from network-byte order to host-byte order. 
    
    ntohs2 Converts a 16-bit quantity from network byte order to host byte order. 
    
    recv1 Receives data from a connected or unconnected socket. 
    
    recvfrom1 Receives data from either a connected or unconnected socket. 
    
    select1 Performs synchronous I/O multiplexing. 
    
    send1 Sends data to a connected socket. 
    
    sendto1 Sends data to either a connected or unconnected socket. 
    
    setsockopt Stores options associated with the specified socket. 
    
    shutdown Shuts down part of a full-duplex connection. 
    
    socket Creates an endpoint for communication and returns a socket descriptor. 
    
    1    The routine can block if acting on a blocking socket. 
    2    The routine is retained for backward compatibility with Windows Sockets 1.1, and should only be used for sockets created with AF_INET address family.

  10. #10
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Hey Dennis, there are API calls for Winsock, take a look at the API-Guide, you know how to translate them from VB to C++ right?

    Is it possible to declare API calls (just like in VB), or do you really have to use those .h files (extra bytes to the actual exe right?)

    ok I have to admit I'm learning VC++ since yesterday

    Hey Dennis, please add me to your ICQ again, or aren't you online anytime?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  11. #11
    Guest
    here is a very simple C++ program that uses windows.. it's a DOS console app...



    Code:
    include <windows.h>
    
    int main()
    {
        MessageBox(NULL, "Test", "Test", MB_OK);
        return 0;
    }
    windows.h has the most common API's already declared...

  12. #12
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    I know they're in windows.h, but can I declare them without the .h file? so my app stays as small as possible?
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  13. #13
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Maybe this can be an answer to Jop's question. Less memory ,smaller exe
    Code:
    All you do is, before you include your header files, 
    
       #define WIN32_LEAN_AND_MEAN
    
    And magically, your program compiles much faster and uses less memory. How? 
    
    All this does is excludes some rarely-used stuff from being processed by the compiler. Specifically, the following header files are not included when WIN32_LEAN_AND_MEAN is defined: 
    
    cderr.h 
    dde.h 
    ddeml.h 
    dlgs.h 
    lzexpand.h 
    mmsystem.h 
    nb30.h 
    rpc.h 
    shellapi.h 
    winperf.h 
    winsock.h, mswsock.h, or winsock2.h 
    wincrypt.h 
    commdlg.h 
    winspool.h 
    ole.h or ole2.h 
    This information is found in windows.h lines 132-165. 
    
    Note that if you want to have the lean and mean advantages, but you need to use something that is excluded in it, such as the Shell API (maybe for system tray) or winsock, it's usually safe to simply #include the appropriate header file in your program after defining WIN32_LEAN_AND_MEAN. 
    
    NOTE: I know the experts out there will complain that there is no reason why WIN32_LEAN_AND_MEAN would reduce memory usage. However, I have found in my tests that it actually does reduce it slightly. If anyone has the free time to do further research, I would update this page accordingly.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  14. #14
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Thanks Vlatko, can you help me with this q?
    http://209.207.250.147/showthread.php?threadid=47496

    thanx

    I gave you the VB source, now you give me the C++ source? Now that's what I call recycling
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width