C++을이용한 TCP/IP
- 최초 등록일
- 2008.12.11
- 최종 저작일
- 2008.03
- 10페이지/ 한컴오피스
- 가격 1,500원
소개글
C를기반으로 TCP/IP의 통신의 예제를 구성하고
소스마다 주석이 달려있다
목차
< TCPClient.cpp >
< TCPServer.cpp >
네트워킹 준비과정
본문내용
<TCPClient.cpp>
#include <winsock2.h>
#include <stdlib.h>
#include <stdio.h>
#define BUFSIZE 512
void err_quit(char *msg)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER|
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, WSAGetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf, 0, NULL);
MessageBox(NULL, (LPCTSTR)lpMsgBuf, msg, MB_ICONERROR);
LocalFree(lpMsgBuf);
exit(-1);
}
void err_display(char *msg)
{
LPVOID lpMsgBuf;
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER|
FORMAT_MESSAGE_FROM_SYSTEM,
NULL, WSAGetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpMsgBuf, 0, NULL);
printf("[%s] %s", msg, (LPCTSTR)lpMsgBuf);
LocalFree(lpMsgBuf);
}
int recvn(SOCKET s, char *buf, int len, int flags)
// 서버로부터 데이터가 넘어올때 계속해서 함수를 호출하여
// 리시브한 데이터는 받은만큼의 버퍼에서 빼주고
{
int received; // ptr 버퍼의 주소를 가리켜서 다음 데이터가 쌓일수 있도록 한다
참고 자료
없음