簡單聊天室

2021-06-05 14:53:53 字數 821 閱讀 2247

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

pthread_t thread[2];

void *send_msg(void *ip_msg)

if(connect(sockfd,(struct sockaddr *)&addr,sizeof(addr))<0)

write(sockfd,send_buffer,strlen(send_buffer));

close(sockfd);

}pthread_exit(null);

}void *rec_msg()

bind(me_sockfd,(struct sockaddr *)&me_addr,sizeof(me_addr));

listen(me_sockfd,5);

int times=0;

while(1)

}read(friend_sockfd,rec_buffer,sizeof(rec_buffer));

printf("friend says:%s\n",rec_buffer);

close(friend_sockfd);

}pthread_exit(null);

}void thread_create()

}void thread_wait()

if(thread[1]!=0)

}int main()

Linux UDP簡單聊天室

伺服器端 include include include include include include include include int sockfd 0 建立結構體用來存放客戶端資訊 typedef struct node node t node t link head node t h ...

go 簡單聊天室

package main import fmt net strings time 建立使用者結構體型別 type cline struct var onlinemap map string cline 建立全域性 channel 傳遞使用者訊息 var message make chan strin...

PHP Swoole 簡單聊天室

效果圖 傳送 開始聊天 php date default timezone set prc users array 建立websocket伺服器物件,監聽0.0.0.0 9502埠 ws new swoole websocket server 0.0.0.0 9502 ws set array wo...