Click here to Skip to main content
15,887,214 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: User detailes from Outlook Pin
Stuart Dootson17-Jun-09 7:15
professionalStuart Dootson17-Jun-09 7:15 
Questioncoding related to mac address Pin
amitkalani117-Jun-09 5:29
amitkalani117-Jun-09 5:29 
QuestionScrollbar in CStatic derived class Pin
kk.tvm17-Jun-09 2:34
kk.tvm17-Jun-09 2:34 
QuestionRe: Scrollbar in CStatic derived class Pin
David Crow17-Jun-09 2:39
David Crow17-Jun-09 2:39 
AnswerRe: Scrollbar in CStatic derived class Pin
kk.tvm17-Jun-09 20:53
kk.tvm17-Jun-09 20:53 
GeneralRe: Scrollbar in CStatic derived class Pin
chandu00418-Jun-09 0:46
chandu00418-Jun-09 0:46 
AnswerRe: Scrollbar in CStatic derived class Pin
KarstenK17-Jun-09 2:59
mveKarstenK17-Jun-09 2:59 
Questionsocket programming using vc++ Pin
rahuljin17-Jun-09 1:35
rahuljin17-Jun-09 1:35 
hi, i am doing some socket programming. the problem is that when i use the port number 80, then the error is 10051 which means Network is unreachable, but my network is working find. also when i use any random number for port, the error is 10061 which means Connection refused.

please guide me. here is my code ----


#include <windows.h>
#include <winsock.h>
#include <stdio.h>

#define NETWORK_ERROR -1
#define NETWORK_OK     0

void ReportError(int, const char *);


int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrevInst, LPSTR lpCmd, int nShow)
{
	WORD sockVersion;
	WSADATA wsaData;
	int nret;
    struct in_addr addr;
    addr.s_addr = inet_addr("127.0.0.1");

	sockVersion = MAKEWORD(1, 1);


	// Initialize Winsock as before
	WSAStartup(sockVersion, &wsaData);


	// Store information about the server
	LPHOSTENT hostEntry;

	hostEntry = gethostbyaddr((char *) &addr, 4, AF_INET);	// Specifying the server by its name;
							// another option: gethostbyaddr()

	if (!hostEntry)
	{
		nret = WSAGetLastError();
		ReportError(nret, "gethostbyaddr()");	// Report the error as before

		WSACleanup();
		return NETWORK_ERROR;
	}


	// Create the socket
	SOCKET theSocket;

	theSocket = socket(AF_INET,			// Go over TCP/IP
			   SOCK_STREAM,			// This is a stream-oriented socket
			   IPPROTO_TCP);		// Use TCP rather than UDP
	if (theSocket == INVALID_SOCKET)
	{
		nret = WSAGetLastError();
		ReportError(nret, "socket()");

		WSACleanup();
		return NETWORK_ERROR;
	}


	// Fill a SOCKADDR_IN struct with address information
	SOCKADDR_IN serverInfo;

	serverInfo.sin_family = AF_INET;

	// At this point, we've successfully retrieved vital information about the server,
	// including its hostname, aliases, and IP addresses.  Wait; how could a single
	// computer have multiple addresses, and exactly what is the following line doing?
	// See the explanation below.

	serverInfo.sin_addr = *((LPIN_ADDR)*hostEntry->h_addr_list);

	serverInfo.sin_port = htons(80);		// Change to network-byte order and
							// insert into port field


	// Connect to the server
	nret = connect(theSocket, (LPSOCKADDR)&serverInfo, sizeof(struct sockaddr));

	if (nret == SOCKET_ERROR)
	{
		nret = WSAGetLastError();
		ReportError(nret, "connect()");

		WSACleanup();
		return NETWORK_ERROR;
	}

    MessageBoxA(NULL, "Great, it is good", "socket Successful", MB_OK);
	// Successfully connected!
    

	// Send/receive, then cleanup:
	closesocket(theSocket);
	WSACleanup();
    return NETWORK_OK;
}


void ReportError(int errorCode, const char *whichFunc)
{
   char errorMsg[92];					// Declare a buffer to hold
							// the generated error message
   
   ZeroMemory(errorMsg, 92);				// Automatically NULL-terminate the string

   // The following line copies the phrase, whichFunc string, and integer errorCode into the buffer
   sprintf_s(errorMsg, "Call to %s returned error %d!", (char *)whichFunc, errorCode);

   MessageBoxA(NULL, errorMsg, "socketIndication", MB_OK);
}

AnswerRe: socket programming using vc++ Pin
Garth J Lancaster17-Jun-09 2:14
professionalGarth J Lancaster17-Jun-09 2:14 
GeneralRe: socket programming using vc++ Pin
rahuljin17-Jun-09 3:04
rahuljin17-Jun-09 3:04 
GeneralRe: socket programming using vc++ Pin
Garth J Lancaster17-Jun-09 3:08
professionalGarth J Lancaster17-Jun-09 3:08 
GeneralRe: socket programming using vc++ Pin
rahuljin17-Jun-09 5:59
rahuljin17-Jun-09 5:59 
GeneralRe: socket programming using vc++ Pin
led mike17-Jun-09 6:11
led mike17-Jun-09 6:11 
GeneralRe: socket programming using vc++ Pin
rahuljin17-Jun-09 7:57
rahuljin17-Jun-09 7:57 
GeneralRe: socket programming using vc++ Pin
Garth J Lancaster17-Jun-09 12:34
professionalGarth J Lancaster17-Jun-09 12:34 
GeneralRe: socket programming using vc++ Pin
rahuljin18-Jun-09 0:12
rahuljin18-Jun-09 0:12 
GeneralRe: socket programming using vc++ Pin
Garth J Lancaster18-Jun-09 0:52
professionalGarth J Lancaster18-Jun-09 0:52 
GeneralRe: socket programming using vc++ Pin
rahuljin18-Jun-09 1:14
rahuljin18-Jun-09 1:14 
AnswerRe: socket programming using vc++ Pin
norish17-Jun-09 2:40
norish17-Jun-09 2:40 
GeneralRe: socket programming using vc++ Pin
rahuljin17-Jun-09 3:17
rahuljin17-Jun-09 3:17 
GeneralRe: socket programming using vc++ Pin
rahuljin24-Jun-09 1:39
rahuljin24-Jun-09 1:39 
GeneralRe: socket programming using vc++ Pin
norish24-Jun-09 6:34
norish24-Jun-09 6:34 
GeneralRe: socket programming using vc++ Pin
rahuljin24-Jun-09 20:34
rahuljin24-Jun-09 20:34 
GeneralRe: socket programming using vc++ Pin
norish25-Jun-09 3:04
norish25-Jun-09 3:04 
GeneralRe: socket programming using vc++ Pin
rahuljin26-Jun-09 20:53
rahuljin26-Jun-09 20:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.