当前位置: 技术问答>linux和unix
小妹求助socket编程!高手请进!
来源: 互联网 发布时间:2016-03-22
本文导语: 用socket 编写一个网络程序,一个TCP server 能同时接受多个client的请求, server有一个计数器,counter, 每当一个client和server连接,server的counter就累加1, 然后把当前的计数器总数返回给client,client打印...
用socket 编写一个网络程序,一个TCP server 能同时接受多个client的请求,
server有一个计数器,counter, 每当一个client和server连接,server的counter就累加1,
然后把当前的计数器总数返回给client,client打印出该数。
多谢了!!
server有一个计数器,counter, 每当一个client和server连接,server的counter就累加1,
然后把当前的计数器总数返回给client,client打印出该数。
多谢了!!
|
server 端程序:
# include
# include
# include
# include
# include
# include
# include
# include
# include "tools.h"
int SockOpenNoAccept ( port, sock )
unsigned int port;
int * sock;
{
int optvar ,optlen;
struct sockaddr_in svr_addr;
* sock = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ) ;
if ( * sock
# include
# include
# include
# include
# include
# include
# include
# include
# include "tools.h"
int SockOpenNoAccept ( port, sock )
unsigned int port;
int * sock;
{
int optvar ,optlen;
struct sockaddr_in svr_addr;
* sock = socket ( AF_INET , SOCK_STREAM , IPPROTO_TCP ) ;
if ( * sock