📄 server.c
字号:
#include "tcpsock.h"
main(argc, argv)
int argc;
char **argv;
{
struct in_addr sin_addr;
int retcode, i;
char buf[32];
(void) signal(SIGINT, CloseMainSock);
(void) signal(SIGQUIT, CloseMainSock);
(void) signal(SIGTERM, CloseMainSock);
if(retcode = InitPassiveSock("TestService")) < 0)
{
printf("InitPassiveSock: error code = %d\n", retcode);exit(-1);
}
while (1)
{
retcode = QuerySocketsMsg();
if (SockMsg.AcceptNum == 1)
{
retcode = AcceptConnection(&sin_addr);
printf("retcode = %d, IP = %s \n", retcode, inet_ntoa(sin_addr.s_addr));
}
else if (SockMsg.AcceptNum == -1)
printf("Daemon Sockets error.\n");
for (i=0; i<SockMsg.ReadNum; i++)
{
if((retcode = RecvPacket(SockMsg.ReadQueuei, buf, 32)) > 0)
printf("sockno %d Recv string = %s \n", SockMsg.ReadQueue[i], buf);
else
CloseConnection(SockMsg.ReadQueue[i];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -