Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

socket programming in C++

Status
Not open for further replies.

sunshine9

Programmer
Aug 1, 2002
21
US
Hello,
I am trying to write a windows service that is monitoring the health of a program that uses port 443. I thought the best way to monitor the program is to try to open a socket on 443, if it cannot, then my program is either not responding or not running, at which point I have to recover my program.

So, I am trying to implement a service to open a socket and listen on this port. However, the code I have written below is trying to open a command window to give me an error, but my service is a console app that is a service and does not allow windows to be created.

Can someone pls tell me what i'm doing wrong or can you explain how to open a socket on a lower-level?

thanks in advance,

bool CMYSocket::GETSocket()
{
TCHAR buffer[256];

CAsyncSocket* pSocket = new CAsyncSocket;
int nPort = 443;
WSADATA WsaData;

if (!AfxSocketInit ( &WsaData))
{
//could not init
return FALSE;
}


if (pSocket->Create( nPort, SOCK_DGRAM ) == 0)
{

DWORD dwErr = GetLastError();
// blah blah do something here
}
else
{
pSocket->Close();
return true;
}
return true;
}
 
Try so:
pSocket->Create( nPort, SOCK_STREAM, FD_ACCEPT ); or add FD_ACCEPT in Your Function.
A good sample with MFC-Sockets is httpsvr on MSDN - it works. You can use sample webster too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top