jonnyboy12 0 Junior Poster in Training

Hello all. I have a small web server that i am using in one of my projects. It is designed to receive a message when somone click on a link containing my ip address. Its used for a email verification/ de-verification. I can run this web server and then type in my ip address into my browser, it will send my web server a message. So it works right. When i try to use it from another computer it will not work. It should, i have turned off all my firewalls, and i am not running through a router, so im hooked up directly to my external ip address. It looks like this,very simple. I couldnt figure how to use these code blocks but this is the code anyways.

#include "stdafx.h"
#include <iostream>
using namespace std;
#include <winsock2.h>
#include <string.h>
#define LISTEN_PORT 80
#define BACKLOG 5
#define PROTOCOL "HTTP/1.1"

int _tmain(int argc, _TCHAR* argv[])
{

bool t=true;
while(t){
WSAData wsadata; if(WSAStartup(MAKEWORD(2,2), &wsadata) != NO_ERROR){
cout<<"Error at WSAStartup\n";
return 0;
}
SOCKET listenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if(listenSocket == INVALID_SOCKET){
cout<<"Error opening socket: "<<WSAGetLastError()<<endl;
WSACleanup();
return 0;
}
//printf(AF_INET);
struct hostent *host_entry;
char server_name[40] = "66.183.101.12";
host_entry = gethostbyname(server_name);
sockaddr_in serverService;
serverService.sin_family = AF_INET;
serverService.sin_addr.s_addr =inet_addr(server_name); //INADDR_ANY;inet_addr(server_name);
serverService.sin_port = htons(LISTEN_PORT);
//cout<< serverService.sin_addr.s_addr;
if(bind(listenSocket, (SOCKADDR*)&serverService, sizeof(serverService)) == SOCKET_ERROR){
cout<<"Error at bind: "<<WSAGetLastError()<<endl;
closesocket(listenSocket);
WSACleanup();
return 0;
}
if(listen(listenSocket, BACKLOG) == SOCKET_ERROR){
cout<<"Error at listen: "<<WSAGetLastError()<<endl;
closesocket(listenSocket);
WSACleanup();
return 0;
}
cout<<"Server connected\n\n";
while(t){
struct sockaddr_in from;
int fromLen = sizeof(from);
SOCKET msgSocket = accept(listenSocket, (struct sockaddr*)&from, &fromLen);
if(msgSocket == INVALID_SOCKET){
cout<<"Error at accept: "<<WSAGetLastError()<<endl;
closesocket(listenSocket);
WSACleanup();
return 0;
}
cout<<"Clinet: address "<<inet_ntoa(from.sin_addr)<<" port: "<<ntohs(from.sin_port)<<endl;
char HTML[] = "<HTML><TITLE></TITLE><BODY><H1>SENT From me!</H1></BODY></HTML>";
char sendBuff[40];
char recvBuff[40];
int bytesSent = 0;
int bytesRecv = 0;
//recieve from client
bytesRecv = recv(msgSocket, recvBuff, (int)strlen(recvBuff), 0);
cout<<"\n"; cout<<"\n"; cout<<"\n";
printf("\nRecieved data = %s ", recvBuff);
cout<<"\n"; cout<<"\n"; cout<<"\n"; cout<<"\n";
//istream in(msgSocket);
//cout<<bytesRecv;
if(bytesRecv == SOCKET_ERROR){
cout<<" Server, error at recv() "<<WSAGetLastError()<<endl;
closesocket(listenSocket);
WSACleanup(); return 0;
}
recv: "<<bytesRecv<<endl;
//sprintf(sendBuff, "%s %d %s", PROTOCOL, 200, "OK");
//send(msgSocket, sendBuff, (int)strlen(sendBuff), 0);
// cout<<"Server sent message: "<<sendBuff<<endl;
//send content
//send(msgSocket, HTML, (int)strlen(HTML), 0);
// cout<<"Server sent message: "<<HTML<<endl;
// closesocket(msgSocket);
}
closesocket(listenSocket);
WSACleanup();
}
return 0;

}

I have been told by someone that this works, and that they had to let it through the windows firewall. I tried doing that,but it still didnt work i i just turned it off fully. Still i get no response. Im on windows seven could there be some other level of firewall im not aware of. Please help me I need to figure this out, before i pull out my hair. Thanks and good bye.

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.