现在的位置: 首页 > 综合 > 正文

linux基础编程 套接字socket 完整的服务器端多线程socket程序

2013年06月16日 ⁄ 综合 ⁄ 共 871字 ⁄ 字号 评论关闭
  1. #include<stdlib.h>   
  2. #include<stdio.h>   
  3. #include<string.h>   
  4. #include<errno.h>   
  5. #include<netdb.h>   
  6. #include<sys/types.h>   
  7. #include<netinet/in.h>   
  8. #include<sys/socket.h>   
  9. #include<sys/wait.h>   
  10. #include<unistd.h>   
  11. #include<pthread.h>   
  12. #include<fcntl.h>  
  13.   
  14. #define __DEBUG  
  15. #ifdef __DEBUG  
  16. #define DBG(fmt,args...) fprintf(stdout,  fmt,  ##args)  
  17. #else  
  18. #define DBG(fmt,args...)  
  19. #endif  
  20. #define ERR(fmt,args...) fprintf(stderr,  fmt,  ##args)  
  21.   
  22. /* 
  23. isStreamQuit == 0 :Start 
  24. isStreamQuit == 1 :Client Quit 
  25. isStreamQuit ==-1 :App Quit 
  26. */  
  27. static int isStreamQuit    = 0;  
  28. static int gStreamServerFd = -1;  
  29. int gStreamClientFd;  
  30.   
  31. #define PORT_SOCKET          9000   //server监听端口  
  32. #define RECV_BUF_MAX_LEN     512  
  33. #define TIME_WAIT            200000     /*200ms*/  
  34.   
  35. /* 
  36. socket发送函数 
  37.  */  
  38. int ScketSend(unsigned char *buf,unsigned int len)  
  39. {  
  40.       

抱歉!评论已关闭.