Hi, i have been making a server for a client I made to connect to. I don't have a static IP, so I need a way for someone on another computer to connect to me without me telling the user what it is every time.
I have tried to just enter another IP in the inet_addr() funtion but then it can't bind.

Please Help...:confused:

SOCKET sServer;
	sServer = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
	if(sServer == INVALID_SOCKET || iError == 1){
		MessageBox(NULL, (LPCTSTR)"Invalid Socket!", (LPCTSTR)"Server::Error", MB_OK|MB_ICONERROR);
		WSACleanup();
		return 0;
}

SOCKADDR_IN sinServer;
	memset(&sinServer, 0, sizeof(sinServer));
	sinServer.sin_family = AF_INET;
	sinServer.sin_addr.s_addr = inet_addr("127.0.0.1"); // Where to start server?
	sinServer.sin_port = htons(1000); // Port 

if(bind(sServer, (LPSOCKADDR)&sinServer, sizeof(sinServer)) == SOCKET_ERROR){
		/* failed at starting server */
		MessageBox(NULL, (LPCTSTR)"Could not bind the server!", (LPCTSTR)"Server::Error", MB_OK|MB_ICONERROR);
		WSACleanup();
		return 0;
}

Recommended Answers

All 5 Replies

Are you directly connected ? No router or gateway?
I used to have a Dlink router that used a free DDns
server at Dlink. The router would report the new address to the server, so it always pointed my box.

It used an address like Http://dlinkddns.mysite.com

I have Dial-up so i have no router and my gateway is myself and sry for replying so long, i had to go

You would have to have some server on the web to report the current IP to, or leave it online all the time. Why not just get a DSL? Those are dynamic also, but don't change that much unless you reset it.

You might want to try something like dyndns.com. Register a free subdomain from a predefined list of domains, and then you can download a client for your operating system, which will update the subdomain to your latest IP address.

Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.