|
我的 程序是这样的 :
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>
#define MYPORT 3490 /*服务器监听端口号 */
#define BACKLOG 10 /* 最大同时连接请求数 */
main()
{
int sock_fd,new_fd; /* 监听socket: sock_fd,数据传输socket:new_fd*/
struct sockaddr_in my_addr;/* 本机地址信息 */
struct sockaddr_in their_addr; /* 客户地址信息 */
int sin_size;
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { /*错误检测 */
perror("socket"); exit(1); }
my_addr.sin_family=AF_INET;
my_addr.sin_port=htons(MYPORT);
my_addr.sin_addr.s_addr = INADDR_ANY;
bzero(&(my_addr.sin_zero),8);
if (bind(sock_fd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))
== -1) {/*错误检测*/
perror("bind"); exit(1); }
if (listen(sock_fd, BACKLOG) == -1) {/*错误检测*/
perror("listen"); exit(1); }
while(1)
{ /* main accept() loop */
sin_size = sizeof(struct sockaddr_in);
if ((new_fd = accept(sock_fd, (struct sockaddr *)&their_addr, &sin_size)) == -1)
{
perror("accept");
continue;
}
printf("server: got connection from %s",inet_ntoa(their_addr.sin_addr));
if (!fork())
{ /* 子进程代码段 */
if (send(new_fd, "Hello, world!", 14, 0) == -1)
perror("send");
close(new_fd);
exit(0);
}
close(new_fd); /* 父进程不再需要该socket */
waitpid(-1,NULL,WNOHANG)>0;/*等待子进程结束,清除子进程所占用资源*/
}
}
编译错误是:
sever.c: In function `main':
sever.c:13: error: stray '\227' in program
sever.c:13: error: stray '\128' in program
sever.c:13: error: stray '\128' in program
sever.c:13: error: stray '\227' in program
sever.c:13: error: stray '\128' in program
sever.c:13: error: stray '\128' in program
sever.c:14: error: stray '\227' in program
sever.c:14: error: stray '\128' in program
sever.c:14: error: stray '\128' in program
sever.c:14: error: stray '\227' in program
sever.c:14: error: stray '\128' in program
sever.c:14: error: stray '\128' in program
sever.c:15: error: stray '\227' in program
sever.c:15: error: stray '\128' in program
sever.c:15: error: stray '\128' in program
sever.c:15: error: stray '\227' in program
sever.c:15: error: stray '\128' in program
sever.c:15: error: stray '\128' in program
sever.c:16: error: stray '\227' in program
sever.c:16: error: stray '\128' in program
sever.c:16: error: stray '\128' in program
sever.c:16: error: stray '\227' in program
sever.c:16: error: stray '\128' in program
sever.c:16: error: stray '\128' in program
sever.c:17: error: stray '\227' in program
sever.c:17: error: stray '\128' in program
sever.c:17: error: stray '\128' in program
sever.c:17: error: stray '\227' in program
sever.c:17: error: stray '\128' in program
sever.c:17: error: stray '\128' in program
sever.c:18: error: stray '\227' in program
sever.c:18: error: stray '\128' in program
sever.c:18: error: stray '\128' in program
sever.c:18: error: stray '\227' in program
sever.c:18: error: stray '\128' in program
sever.c:18: error: stray '\128' in program
sever.c:19: error: stray '\227' in program
sever.c:19: error: stray '\128' in program
sever.c:19: error: stray '\128' in program
sever.c:19: error: stray '\227' in program
sever.c:19: error: stray '\128' in program
sever.c:19: error: stray '\128' in program
sever.c:20: error: stray '\227' in program
sever.c:20: error: stray '\128' in program
sever.c:20: error: stray '\128' in program
sever.c:20: error: stray '\227' in program
sever.c:20: error: stray '\128' in program
sever.c:20: error: stray '\128' in program
sever.c:21: error: stray '\227' in program
sever.c:21: error: stray '\128' in program
sever.c:21: error: stray '\128' in program
sever.c:21: error: stray '\227' in program
sever.c:21: error: stray '\128' in program
sever.c:21: error: stray '\128' in program
sever.c:22: error: stray '\227' in program
sever.c:22: error: stray '\128' in program
sever.c:22: error: stray '\128' in program
sever.c:22: error: stray '\227' in program
sever.c:22: error: stray '\128' in program
sever.c:22: error: stray '\128' in program
sever.c:23: error: stray '\227' in program
sever.c:23: error: stray '\128' in program
sever.c:23: error: stray '\128' in program
sever.c:23: error: stray '\227' in program
sever.c:23: error: stray '\128' in program
sever.c:23: error: stray '\128' in program
sever.c:24: error: stray '\227' in program
sever.c:24: error: stray '\128' in program
sever.c:24: error: stray '\128' in program
sever.c:24: error: stray '\227' in program
sever.c:24: error: stray '\128' in program
sever.c:24: error: stray '\128' in program
sever.c:25: error: stray '\227' in program
sever.c:25: error: stray '\128' in program
sever.c:25: error: stray '\128' in program
sever.c:25: error: stray '\227' in program
sever.c:25: error: stray '\128' in program
sever.c:25: error: stray '\128' in program
sever.c:26: error: stray '\227' in program
sever.c:26: error: stray '\128' in program
sever.c:26: error: stray '\128' in program
sever.c:26: error: stray '\227' in program
sever.c:26: error: stray '\128' in program
sever.c:26: error: stray '\128' in program
sever.c:27: error: stray '\227' in program
sever.c:27: error: stray '\128' in program
sever.c:27: error: stray '\128' in program
sever.c:27: error: stray '\227' in program
sever.c:27: error: stray '\128' in program
sever.c:27: error: stray '\128' in program
sever.c:30: error: stray '\227' in program
sever.c:30: error: stray '\128' in program
sever.c:30: error: stray '\128' in program
sever.c:30: error: stray '\227' in program
sever.c:30: error: stray '\128' in program
sever.c:30: error: stray '\128' in program
sever.c:31: error: stray '\227' in program
sever.c:31: error: stray '\128' in program
sever.c:31: error: stray '\128' in program
sever.c:31: error: stray '\227' in program
sever.c:31: error: stray '\128' in program
sever.c:31: error: stray '\128' in program
sever.c:33: error: stray '\227' in program
sever.c:33: error: stray '\128' in program
sever.c:33: error: stray '\128' in program
sever.c:33: error: stray '\227' in program
sever.c:33: error: stray '\128' in program
sever.c:33: error: stray '\128' in program
sever.c:36: error: stray '\227' in program
sever.c:36: error: stray '\128' in program
sever.c:36: error: stray '\128' in program
sever.c:36: error: stray '\227' in program
sever.c:36: error: stray '\128' in program
sever.c:36: error: stray '\128' in program
sever.c:37: error: stray '\227' in program
sever.c:37: error: stray '\128' in program
sever.c:37: error: stray '\128' in program
sever.c:37: error: stray '\227' in program
sever.c:37: error: stray '\128' in program
sever.c:37: error: stray '\128' in program
sever.c:39: error: stray '\227' in program
sever.c:39: error: stray '\128' in program
sever.c:39: error: stray '\128' in program
sever.c:39: error: stray '\227' in program
sever.c:39: error: stray '\128' in program
sever.c:39: error: stray '\128' in program
sever.c:40: error: stray '\227' in program
sever.c:40: error: stray '\128' in program
sever.c:40: error: stray '\128' in program
sever.c:40: error: stray '\227' in program
sever.c:40: error: stray '\128' in program
sever.c:40: error: stray '\128' in program
sever.c:44: error: stray '\227' in program
sever.c:44: error: stray '\128' in program
sever.c:44: error: stray '\128' in program
sever.c:44: error: stray '\227' in program
sever.c:44: error: stray '\128' in program
sever.c:44: error: stray '\128' in program
sever.c:45: error: stray '\227' in program
sever.c:45: error: stray '\128' in program
sever.c:45: error: stray '\128' in program
sever.c:45: error: stray '\227' in program
sever.c:45: error: stray '\128' in program
sever.c:45: error: stray '\128' in program
好像是错误但是我不知道是什么错误 希望哪位大虾能给我一些指点。 |
|