LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 1002|回复: 3

求助一个socket程序错误

[复制链接]
发表于 2007-4-5 16:04:29 | 显示全部楼层 |阅读模式
我的 程序是这样的 :
#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
好像是错误但是我不知道是什么错误 希望哪位大虾能给我一些指点。
发表于 2007-4-5 17:53:17 | 显示全部楼层

是因为有些字符是全角的吧

是不是把某些符号象是大括号打成全角的了?
回复 支持 反对

使用道具 举报

发表于 2007-4-5 19:18:58 | 显示全部楼层
用什么编辑器?发现是大部分行的前面有一两个不可见的字符,删掉就可以了。
怀疑这个代码最初是从网页上copy下来的。。。
回复 支持 反对

使用道具 举报

发表于 2007-4-5 19:32:46 | 显示全部楼层
怀疑这个代码最初是从网页上copy下来的。。。

同意楼上的.
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表