소켓통신에서 도메인으로 접속할경우 관련 질문입니다.
글쓴이: kimyh / 작성시간: 월, 2006/10/23 - 1:34오전
./client school.com
지금 이런식으로 접속하고 있는데 ./client 라고만 하면 접속할수 있도록 하고 싶습니다.
도메인 school.com을 내부에서 #define PORT 8080 처럼 define 해주어 접속하는 방법이 없을까요.
이런식으로 접속하는 소켓통신 소스는 아무리 찾아봐도 없군요.
아래는 소겟접속 관련부분 소스 일부입니다.
도와 주시면 감사하겠습니다.
//헤더파일 include #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <netdb.h> #include <sys/types.h> #include <netinet/in.h> #include <sys/socket.h> #include <errno.h> //변수 선언 #define PORT 8080 // the port client will be connecting to #define MAXDATASIZE 100 // max number of bytes we can get at once #define HOSTNAME school.com . . . . struct hostent *he; struct sockaddr_in their_addr; // connector's address information if (argc != 2) { fprintf(stderr,"usage: client hostname\n"); exit(1); } if ((he=gethostbyname(argv[1])) == NULL) { // get the host info perror("gethostbyname"); exit(1); } if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } their_addr.sin_family = AF_INET; // host byte order their_addr.sin_port = htons(PORT); // short, network byte order their_addr.sin_addr = *((struct in_addr *)he->h_addr); . . . . .
Forums:
살며 그리고
살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.
살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.
잠깐만 살펴보시면 될텐데요..
man 3 gethostbyname
----
:LOL:
http://luna.onionmixer.net
""만 묶으면 될 일입니다.
#define HOSTNAME "school.com"
두분 답변 감사합니다.
밤 늦은 시간임에도 불구하고 답변 주신것 정말 감사합니다.
두분 알려주신대로 해서 성공 했습니다.
정말 감사드립니다.
살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.
살며 그리고 사랑하며...
정보는 공유할때 그 가치가 있는것.....
나의 조그만 지식공유는 남에게 엄청난 기쁨을 안겨 준다.
댓글 달기