#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<winsock2.h>
#pragma comment(lib, "ws2_32.lib")
void ErrorHandling(char *message);
int main(int argc, char **argv)
{
WSADATA wsaData;
SOCKET hSocket;
char message[30];
int strLen;
SOCKADDR_IN servAddr;
/*if(argc!=3){
printf("Usage : %s <IP> <port>\n", argv[0]);
exit(1);
}*/
if(WSAStartup(MAKEWORD(2,2), &wsaData) !=0)
ErrorHandling("WSAStartup() error!");
hSocket=socket(PF_INET, SOCK_STREAM, 0);
if(hSocket==INVALID_SOCKET)
ErrorHandling("hSocketet() error");
memset(&servAddr, 0, sizeof(servAddr));
servAddr.sin_family=AF_INET;
servAddr.sin_addr.s_addr=inet_addr("127.0.0.1");
servAddr.sin_port=htons(3000);
if( connect(hSocket, (SOCKADDR*)&servAddr, sizeof(servAddr))==SOCKET_ERROR)
ErrorHandling("connect() error!");
strLen=recv(hSocket, message, sizeof(message)-1, 0);
if(strLen==-1)
ErrorHandling("read() error!");
message[strLen]=0;
printf("Message from server : %s\n",message);
closesocket(hSocket);
WSACleanup();
return 0;
}
void ErrorHandling(char *message)
{
fputs(message, stderr);
fputc('\n',stderr);
exit(1);
}
'네트워크 프로그래밍' 카테고리의 다른 글
UDP daytime 에코서버 프로그래밍! (0) | 2009.09.18 |
---|---|
TCP/IP echo_client programming! (0) | 2009.09.18 |
TCP/IP echo server programming ! (0) | 2009.09.18 |
윈도우에서 서버 구축하기 (0) | 2009.09.15 |
FILE * pfile = fopen(pfilename, "rt"); 에서 "rt"부분 설명 (0) | 2009.09.15 |