|
프리 컴파일 헤더를 사용한 VC 프로젝트의 소스 같아 보이네요.. stdafx 부분을 지우고 필요한 Header 를 추가 해주시면 됩니다.
보기 님이 쓰신 글 :
: 제가 소켓을 자바와 C로 된 소스인데 C에서 계속 "cannot open include file: 'stdafx.h': No such file or directory" 오류가 나오네요
: 'stdafx.h'가 없다고 나오는데 어떻게 하면 해결이 가능할까요
: ======================================================
: /*
: ** client.c -- a stream socket client demo
: */
: #include <stdafx.h>
: #include <stdio.h>
: #include <stdlib.h>
: // #include <unistd.h>
: #include <errno.h>
: #include <string.h>
: // #include <netdb.h>
: #include <sys/types.h>
: #include <winsock2.h>
: // #include <netinet/in.h>
: // #include <sys/socket.h>
:
: // #define PORT 3490 // the port client will be connecting to
: #define IP "210.115.167.37"
: #define PORT 8080
:
: #define MAXDATASIZE 1024 // max number of bytes we can get at once
:
: struct test_str
: {
:
: int d;
: char opr;
: char aa;
: double fl;
: double db;
: };
:
:
: int swap(int i)
: {
: int byte0 = i & 0xff;
: int byte1 = (i>>8) & 0xff;
: int byte2 = (i>>16) & 0xff;
: int byte3 = (i>>24) & 0xff;
:
: return (byte0<<24) | (byte1<<16) | (byte2<<8) | byte3;
: };
:
:
: int main(int argc, char *argv[])
: {
: SOCKET _socket;
: struct test_str ts;
: int numbytes;
: char buf[MAXDATASIZE];
: struct sockaddr_in their_addr; // connector's address information
:
: WSADATA wsa;
:
: if(WSAStartup(MAKEWORD(2,2), &wsa) != 0){
: fprintf (stderr, "[ERROR0] : << \n");
: exit(1);
: }
:
:
: if ((_socket = socket(AF_INET, SOCK_STREAM, 0)) == INVALID_SOCKET ) {
: fprintf (stderr, "[%d] Socket_Create() \n", WSAGetLastError());
: exit(1);
: }
:
: their_addr.sin_family = AF_INET; // host byte order
: their_addr.sin_port = htons(8000); // short, network byte order
: their_addr.sin_addr.s_addr = inet_addr("210.115.167.37"); //*((struct in_addr *)he->h_addr);
: memset(&(their_addr.sin_zero), '\0', 8); // zero the rest of the struct
:
: if (connect(_socket, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == SOCKET_ERROR) {
: fprintf (stderr, " Socket_Connect() Error : [%d]\n", WSAGetLastError());
: exit(1);
: }
:
: ts.d = 0;
: ts.opr = 'z';
: ts.aa = 'K';
: ts.fl = 2.35;
: ts.db = 19.445634;
:
: //보내기
: if (send(_socket, (const char *)&ts, sizeof(ts), 0) == SOCKET_ERROR){
: fprintf (stderr, " Socket_Send() Error : [%d]\n", WSAGetLastError());
: exit(1);
: }
:
: //받기
: if ((numbytes=recv(_socket, buf, MAXDATASIZE-1, 0)) == SOCKET_ERROR) {
: fprintf (stderr, " Socket_Recv() Error : [%d]\n", WSAGetLastError());
: exit(1);
: }
:
: printf("Received: [%s]",buf);
:
: closesocket(_socket);
:
: return 0;
: }
: ===========================================
|