看板 HSNU_979 關於我們 聯絡資訊
以下的code是server端的 上一篇是client端的 也順便一下吧...如果不行compile 請告訴我結果吧...我想知道原因 #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <netdb.h> #define SERVER_PORT 5432 #define MAX_PENDING 5 #define MAX_LINE 256 int main(){ struct sockaddr_in sin; char buf[MAX_LINE]; int len; int s, new_s; /*build address data structure*/ bzero((char *)&sin, sizeof(sin)); sin.sin_family = AF_INET; sin.sin_addr.s_addr = INADDR_ANY; sin.sin_port = htons(SERVER_PORT); /*setup passive open*/ if((s = socket(PF_INET, SOCK_STREAM, 0)) <0 ){ perror("simplex-talk: socket"); exit(1); } if((bind(s, (struct sockaddr *)&sin, sizeof(sin))) < 0){ perror("simplex-talk: bind"); exit(1); } listen(s, MAX_PENDING); /*wait for connection, then receive and print text*/ while(1){ if((new_s = accept(s, (Struct sockaddr *)&sin, &len)) <0 ){ perror("simplex-talk: accept"); exit(1); } while(len = recv(new_s, buf, sizeof(buf), 0)) fputs(buf, stdout); close(new_s); } } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.192.240.85