Results 1 to 5 of 5

Thread: WinSock -- Next Hurdle =oD

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Location
    Miami
    Posts
    22

    Cool WinSock -- Next Hurdle =oD

    Alright, so here I am reading all I can on winsock and when I finally try out some examples I get undefined errors from the linkers output (i'm using Dev C++ 4 by Bloodshed). I run WinXP pro and I think that could be the problem or maybe it's something else? Thought maybe you fine people could help.

    Here's the example I was trying out from "Johnnies Winsock Tutorial"

    PHP Code:
    #include <winsock.h>        // winsock.h always needs to be included
    #include <stdio.h>


    int main(int argcchar** argv) {
        
    WORD version MAKEWORD(1,1);
        
    WSADATA wsaData;
        
    int nRet;


        
    //
        // First, we start up Winsock
        //
        
    WSAStartup(version, &wsaData);


        
    //
        // Next, create the socket itself
        //
        
    SOCKET listeningSocket;

        
    listeningSocket socket(AF_INET,        // Go over TCP/IP
                     
    SOCK_STREAM,        // Socket type
                     
    IPPROTO_TCP);        // Protocol
        
    if (listeningSocket == INVALID_SOCKET) {
            
    printf("Error at socket()");
            return 
    0;
        }

        
        
    //
        // Use SOCKADDR_IN to fill in address information
        //
        
    SOCKADDR_IN saServer;
        
        
    saServer.sin_family AF_INET;
        
    saServer.sin_addr.s_addr INADDR_ANY;        // Since this is a server, any address will do
        
    saServer.sin_port htons(8888);        // Convert int 8888 to a value for the port field


        //
        // Bind the socket to our local server address
        //
            
    nRet bind(listeningSocket, (LPSOCKADDR)&saServersizeof(struct sockaddr));
        if (
    nRet == SOCKET_ERROR) {
            
    printf("Error at bind()");
            return 
    0;
        }


        
    //
        // Make the socket listen
        //
        
    nRet listen(listeningSocket10);        // 10 is the number of clients that can be queued
        
    if (nRet == SOCKET_ERROR) {
            
    printf("Error at listen()");
            return 
    0;
        }
        
        
        
    //
        // Wait for a client
        //
        
    SOCKET theClient;

        
    theClient accept(listeningSocket,
                   
    NULL,            // Wait for a specific address to connect; here there is none
                   
    NULL);
        if (
    theClient == INVALID_SOCKET) {
            
    printf("Error at accept()");
            return 
    0;
        }


        
    // Send/receive from the client, and finally:
        
        
    closesocket(theClient);
        
    closesocket(listeningSocket);


        
    //
        // Shutdown Winsock
        //
        
    WSACleanup();

    The Errors..

    Code:
    c:\winsock c++\winsock1\tcpclient\untitled1.o(.text+0x6c):untitled1.cpp: undefined reference to `WSAStartup@8'
    c:\winsock c++\winsock1\tcpclient\untitled1.o(.text+0x7d):untitled1.cpp: undefined reference to `socket@12'
    c:\winsock c++\winsock1\tcpclient\untitled1.o(.text+0xcc):untitled1.cpp: undefined reference to `htons@4'
    c:\winsock c++\winsock1\tcpclient\untitled1.o(.text+0xf0):untitled1.cpp: undefined reference to `bind@12'
    c:\winsock c++\winsock1\tcpclient\untitled1.o(.text+0x12d):untitled1.cpp: undefined reference to `listen@8'
    c:\winsock c++\winsock1\tcpclient\untitled1.o(.text+0x16f):untitled1.cpp: undefined reference to `accept@12'
    c:\winsock c++\winsock1\tcpclient\untitled1.o(.text+0x1ab):untitled1.cpp: undefined reference to `closesocket@4'
    c:\winsock c++\winsock1\tcpclient\untitled1.o(.text+0x1bd):untitled1.cpp: undefined reference to `closesocket@4'
    c:\winsock c++\winsock1\tcpclient\untitled1.o(.text+0x1c5):untitled1.cpp: undefined reference to `WSACleanup@0'
    Bleh.. Any ideas anyone?

  2. #2
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    u have to link to ws2_32.lib i think it is. i dont know how u do that in ur compiler though.

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Mar 2002
    Location
    Miami
    Posts
    22
    That was pretty dull of me, heh it said I needed to link it right up top. Thanks

  4. #4
    Fanatic Member nabeels786's Avatar
    Join Date
    Jul 2001
    Location
    New York
    Posts
    919
    its wsock32.lib
    Visit www.fragblast.com
    Gaming, forums, and a online RPG/Battle system




    (__Flagg) DOT NET? is this a Hindi Dating service?

  5. #5
    Frenzied Member
    Join Date
    Jun 2000
    Location
    England, Buckingham
    Posts
    1,341
    It depends, wsock32.lib is for winsock 1.1/2 i think and and ws2_32.lib u have to use if u are using winsock version 2 or higher

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