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++ MFC WinSock troubles

Options
  • 22-11-2001 11:53pm
    #1
    Registered Users Posts: 1,842 ✭✭✭


    I'm using VC++ 6.0, trying to get some simple winsock code working... it's refusing to.

    Connect() does not return true, so I call GetLastError() on that socket, and I'm given the error code "4198694".

    I've searched everywhere for what that error code means, and I can't find it!

    (MSDN docs, knowledgebase, google...)

    	if(m_sMySocket.Create())
    	{
    		Output("Created socket. Connecting...");
    		
    		if (m_sMySocket.Connect("igor", 80))
    		{
    			Output("Connected.");
    		} else {
    			char buf[50];
    			sprintf(buf, "Failed to connect. (%d)", m_sMySocket.GetLastError);
    			Output(buf);
    		}
    
    
    
    
    	} else {
    		Output("Could not create socket.");
    	}
    
    

    (Output() is a function that adds text to a textbox on my dialog, and "igor" is a host on my network. Same error if I use an IP there.)

    I'm following what it says in Teach Yourself C++ in 21 Days, so I'm stumped.


Comments

  • Closed Accounts Posts: 285 ✭✭marauder


    I have done simialr stuff to this in Java rather than C++
    If I understand what you are trying to do, its a client connecting to port 80 on your server igor.
    This begs the question have you a server listening on port 80 on igor?
    Also IMHO I suggest using a port other than 80 as this is typically used for internet traffic........


  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    As the man says, for that code to work, the host "igor" must be listening on port 80, ie be running a webserver.

    Couple of things to try from the DOS cmd line:

    ping igor // is it alive?

    telnet igor 80 // can you connect to that port?
    (To check if it's a normal webserver type "GET /" after the above telnet command).


    Also, check if "m_sMySocket.GetLastError" does in fact return an integer, it's unlikely, but it may be a pointer to a message buffer (looks big enough).

    hth,
    Al.


  • Registered Users Posts: 2,149 ✭✭✭dazberry


    For socket errors (or not), GetLastError (or WSAGetLastError) should return errors in the 100xx range, and it doesn't matter if the host server is available or not, you should still get an meaningful error message.

    i.e.
    WSAETIMEDOUT (10060) - Connection timed out
    WSAECONNREFUSED (10061) - Connection refused

    Errors from GetLastError out of that range are normally other Windows errors, but these values only go up to around 6000.

    However as Trojan point out, you may be returning a reference to a value, not the value itself, 4198694 looks more like a pointer to something rather than an actual value, and is definitely not an error code.

    DaZ


  • Registered Users Posts: 1,842 ✭✭✭phaxx


    If it were something as simple as the other end not responding, it would have returned a better error message.

    The server is up, apache is running on port 80, "igor" resolves to "192.168.1.1" from any machine here, so it's not any of that. All other sockets apps work fine on this machine, so it's nothing to do with the connection.


  • Registered Users Posts: 16,413 ✭✭✭✭Trojan


    Originally posted by phaxx
    If it were something as simple as the other end not responding, it would have returned a better error message.

    Ok, I thought that it may be the address of the error message its returning, not the error string itself, but I think that it's int GetLastError() -- don't have a windows machine to confirm this.

    So maybe the error code is getting garbaged somewhere... try stepping through the code with the debugger turned on[1] and see if the correct value is in your string "buf".
    Originally posted by phaxx

    The server is up, apache is running on port 80, "igor" resolves to "192.168.1.1" from any machine here, so it's not any of that. All other sockets apps work fine on this machine, so it's nothing to do with the connection.

    With sockets it's always a coding problem or a network problem. Take the Sherlock Holmes approach and eliminate possible errors.

    Al.

    1. If you don't know how to use the debugger, find out. It can save days of time, the debugger is your friend :)


  • Advertisement
Advertisement