This commit is contained in:
weidongshan
2024-08-11 16:57:25 +08:00
parent fbfe070b0b
commit a151034d3b
6 changed files with 13 additions and 0 deletions

View File

@@ -22,6 +22,7 @@ int main(int argc, char **argv)
int iRet;
unsigned char ucSendBuf[1000];
int iSendLen;
int iRecvLen;
if (argc != 2)
{
@@ -60,6 +61,13 @@ int main(int argc, char **argv)
close(iSocketClient);
return -1;
}
iRecvLen = recv(iSocketClient, ucSendBuf, 999, 0);
if (iRecvLen > 0)
{
ucSendBuf[iRecvLen] = '\0';
printf("From server: %s\n", ucSendBuf);
}
}
}

View File

@@ -27,6 +27,7 @@ int main(int argc, char **argv)
struct sockaddr_in tSocketClientAddr;
int iRet;
int iAddrLen;
int cnt;
int iRecvLen;
unsigned char ucRecvBuf[1000];
@@ -65,12 +66,14 @@ int main(int argc, char **argv)
{
iAddrLen = sizeof(struct sockaddr);
iSocketClient = accept(iSocketServer, (struct sockaddr *)&tSocketClientAddr, &iAddrLen);
if (-1 != iSocketClient)
{
iClientNum++;
printf("Get connect from client %d : %s\n", iClientNum, inet_ntoa(tSocketClientAddr.sin_addr));
if (!fork())
{
cnt = 0;
/* 子进程的源码 */
while (1)
{
@@ -85,6 +88,8 @@ int main(int argc, char **argv)
{
ucRecvBuf[iRecvLen] = '\0';
printf("Get Msg From Client %d: %s\n", iClientNum, ucRecvBuf);
sprintf(ucRecvBuf, "Get Msg cnt %d", cnt++);
send(iSocketClient, ucRecvBuf, strlen(ucRecvBuf), 0);
}
}
}