IP Address

Posts 1–5 of 5 · Page 1 of 1
IP Address
My winsock client that i gave to somebody on another LAN network won't work. I know it is a problem with the ip address. I tried to connect using my global ip, but it didn't work, and then i gave him the client that connects with the local ip and it still didn't work. Here is the conflicting (especially look at the sockaddr_in structure) code:


Code:
int SendFullScoreReport(char* buffer)
{
    	WSAData wsa;
	SOCKET sock;

	if(WSAStartup(MAKEWORD(2,2), &wsa) != 0)
	{
		cout<<"An error has occured trying to initialize WinSock.";
		WSACleanup();
		cin.get();
		return 0;
	}

	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

	if(sock == INVALID_SOCKET)
	{
		cout<<"Socket is invalid.";
		WSACleanup();
		cin.get();
		return 0;
	}

	struct hostent *host;
	if((host=gethostbyname("localhost"))==NULL)
	{
		std::cout<<"Failed to resolve hostname.\r\n";
		WSACleanup();
		system("PAUSE");
		return 0;
	}

	SOCKADDR_IN sockaddr;

	sockaddr.sin_family = AF_INET;
	sockaddr.sin_port = htons(8888);
	sockaddr.sin_addr.S_un.S_addr = inet_addr("xx.xx.xx.47");

	if(connect(sock, (SOCKADDR*) &sockaddr, sizeof(sockaddr)) != 0)
	{
		cout<<"Failed to connect to server.";
		WSACleanup();
		cin.get();
		return 0;
	}
	
	cout<<"\nSending the full score report.";
	
	send(sock, "Print", 5, 0);
    
    Sleep(1000);
    
    send(sock, buffer, strlen(buffer), 0);
    
    cout<<"\nThe Full Score Report has been successfully sent.\n";
    
    
    
    closesocket(sock);
    WSACleanup();
    system("PAUSE");
    return 0;
}

Ooops, I forgot to mention that I already did port forwarding, and it still didn't work.
I am in kind of a hurry because it is for church in 2 days and i want to surprise them. Thanks in advance.
Less than 2 hours between your first post and second. Please keep in mind that we aren't being paid by anyone to post here, or even help, for that matter.

Code:
inet_addr("xx.xx.xx.47");
must be a valid IP address.

Though not pretty, the above code works and is completely functional. I have just compiled it and tested it with my own TCP server, and I don't see any issues with the compiled application.
Quote Originally Posted by freedompeace View Post
Less than 2 hours between your first post and second. Please keep in mind that we aren't being paid by anyone to post here, or even help, for that matter.

Code:
inet_addr("xx.xx.xx.47");
must be a valid IP address.

Though not pretty, the above code works and is completely functional. I have just compiled it and tested it with my own TCP server, and I don't see any issues with the compiled application.
First of all, I really appreciate that you replied so quickly, and I understand that you guys aren't getting anything out of helping me so I really appreciate that you answered despite my rudeness.

Second of all, I know that the code is functional, but nobody can use it outside of my network. That's the issue I have been having for a while. I don't know why it isn't working even though i port forwarded.

I typed my gateway address in the url box of my browser and it took me to my router settings. I have a 2wire router. I clicked on firewall and then clicked on settings and then made a new user defined application. When it asked me for what port it will connect on i set it to "8888 to: 8888" and then connection timeout i set it for 8400. Then i set the type as "IRC" and then all the other kinds. Is there any reason why it wouldn't work?


EDIT:===============================

Ok, I got it to work with my global ip. It wasn't working before. The only problem is that i sent it to a friend and he opened and it didn't connect. Why would that happen? Any ideas?
nvrmind, prob solved. it was a port forwarding problem
Posts 1–5 of 5 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Talk with us