|
From: Greg E. <gre...@ho...> - 2002-06-14 12:27:13
|
Hiya
Im trying to use this source code, but when i go to compile i get loads of
linker errors, how do i go about correcting these. Im a novice so simple
instructions would be useful. Thanks. Ive included the source code below.
Thanks
#include <winsock.h>
#include <stdio.h>
int main(int argc, char** argv) {
WORD version = MAKEWORD(1,1);
WSADATA wsaData;
int nRet;
//
// Start up Winsock as before
//
WSAStartup(version, &wsaData);
//
// Store information about the server
//
LPHOSTENT lpHostEntry;
lpHostEntry = gethostbyname("www.hal-pc.org"); // Specifying server
by its name
if (lpHostEntry == NULL) {
printf("Error at gethostbyname()");
return 0;
}
//
// Create the socket
//
SOCKET theSocket;
theSocket = socket(AF_INET, // Go over TCP/IP
SOCK_STREAM, // Socket type
IPPROTO_TCP); // Protocol
if (theSocket == INVALID_SOCKET) {
printf("Error at socket()");
return 0;
}
//
// Use SOCKADDR_IN to fill in address information
//
SOCKADDR_IN saServer;
saServer.sin_family = AF_INET;
saServer.sin_addr = *((LPIN_ADDR)*lpHostEntry->h_addr_list);
// ^ Address of the server being inserted into the address field
saServer.sin_port = htons(80);
//
// Connect to the server
//
nRet = connect(theSocket,
(LPSOCKADDR)&saServer, // Server address
sizeof(struct sockaddr)); // Length of address structure
if (nRet == SOCKET_ERROR) {
printf("Error at connect()");
return 0;
}
// Successfully connected!
closesocket(theSocket);
//
// Shutdown Winsock
//
WSACleanup();
}
_________________________________________________________________
Chat with friends online, try MSN Messenger: http://messenger.msn.com
|