客户端:
/**************************************
客户端
**************************************/
#include <stdio.h>
#include <sys/types.h> /* See NOTES */
#include <sys/socket.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/ip.h> /* superset of previous */
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <pthread.h>
#include <stdlib.h>
int sockfd;
void *read_msg (void *arg)
{
while(1)
{
char buf[1024] = {
0};
read(sockfd, buf, 1024);
printf("收到的数据:%s\n", buf);
if (strcmp(buf, "exit") == 0)
{
printf("退出聊天!\n");
exit(0);
}
}
}
int main(int argc, char **argv)
{
if(argc != 2)
{
perror("input IP:");
return -1;
}
//1.创建网络通信对象