Linux-Socket编程实例精编.docVIP

  • 2
  • 0
  • 约5.1千字
  • 约 5页
  • 2019-02-02 发布于四川
  • 举报
Linux Socket编程实例(一个Hello World程序) 在Linux下写了个小的socket程序,分为客户端和服务器端,服务端开一个端口(2000),做为一个daemon,等待客户的连接请求.一旦有客户连接,服务器端打印出客户端的IP地址和端口,并且向服务器端发送欢迎信息和时间.下面是服务端的代码(tcpserver.c).由于这只是个简单的程序,所以只用了单线程实现! Cpp代码 /** ? ?*?Tcp?Server?program,?It?is?a?simple?example?only. ? ?*?zhengsh?200520602061?2 ? ?*?when?client?connect?to?server,?send?a?welcome?message?and?timestamp?in?server. ? ?*/?? ? ?? #include?stdio.h ?? #include?sys/socket.h ?? #include?unistd.h ?? #include?sys/types.h ?? #include?netinet/in.h ?? #include?stdlib.h ?? #include?time.h ?? ? ?? #define?SERVER_PORT?20000?//?define?the?defualt?connect?p

文档评论(0)

1亿VIP精品文档

相关文档