Jump to content
  • Advertisement
Sign in to follow this  
Slug

LoopBack Address dosen't work for me!

This topic is 4825 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, i'm trying to make a WinSock network program run on a single computer using the LoopBack address but it dosen't seem to work (It dosent return true on connect). I have WinXP on my machine. Here the code: #pragma comment(lib, "WSOCK32.lib") #include <iostream> #include <winsock.h> #include <string> using namespace std; int main() { string ip; int port; //Define ip and port ip = "127.0.0.1"; port = 80; //Define containers for the data and version WSADATA sockData; WORD version; SOCKET conn; //Define container for exceptions int error; //Make version version = MAKEWORD(1,1); //Start winsock API with version and data as buffer (&) error = WSAStartup(version, &sockData); //Start the socket conn = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); //Once socket is established give values to nodes SOCKADDR_IN Winsock; Winsock.sin_family = AF_INET; //Winsock connection port Winsock.sin_port = htons(port); //Winsock connection IP Winsock.sin_addr.s_addr = inet_addr(ip.c_str()); //Connect on the socket if(connect(conn, (SOCKADDR*) &Winsock, sizeof(Winsock)) == SOCKET_ERROR) { //if an error return the error number cout << "An exception has occured (" << WSAGetLastError() << ")\n"; //Cleanup socket WSACleanup(); system("PAUSE"); return EXIT_FAILURE; } cout << "Socket Connection established\n"; //Close socket connection closesocket(conn); cout << "Socket Connection closed\n"; system("pause"); return EXIT_SUCCESS; }

Share this post


Link to post
Share on other sites
Advertisement
What do you mean it doesn't work? You won't be able to connect to anything unless you're running a server. LoopBack means it refers to your machine - the machine still has to have something running to accept the connection.

Share this post


Link to post
Share on other sites
What did you mean by "connect to a server"??? The loopback address isn't for
testing your app withont being on the internet???

Share this post


Link to post
Share on other sites
You need to create a program that listens on the port your client program is trying to connect to. This page has some info on doing it.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!