Linux下基於socket多執行緒併發通訊的實現

2021-05-25 10:56:26 字數 1752 閱讀 3226

編譯伺服器端程式

pthread_server.c

$gcc pthread_server.c –o server –lpthread

編譯客戶端程式

pthread_client.c:

$gcc pthread_client.c –o client

編譯在開發板上跑的客戶端程式:

$arm-linux-gcc client.c –o arm_client

先啟動伺服器端的程式

server:

$./server

開啟另乙個終端,啟動客戶端的程式

client:

$./client 127.0.0.1 9734

arm_client

放到開發板上,啟動

arm_client:

$./arm_client 219.222.170.9 9734

結果

:

伺服器端:

tongs@tong's-desktop:~/c_c++_program/sock_inet_comm2$ ./server

server waiting for connect

receive from client is client

receive from client is client

receive from client is arm_client

receive from client is arm_client

客戶端:

tongs@tong's-desktop:~/c_c++_program/sock_inet_comm2$ ./client 127.0.0.1 9734

client

client

exit

開發板伺服器端

[/mnt/yaffs/nfs_share/sock_tcp/thread_socket]./arm_client  219.222.170.9 9734

arm_client

arm_client

exit

Linux下基於C C 的Socket程式設計例項

socket程式設計例項 例項中的伺服器通過socket連線向客戶端傳送字串 hello,you are connected 只要在伺服器上執行該伺服器軟體,在客戶端執行客戶軟體,客戶端就會收到該字串。該伺服器軟體 如下 include include include include include...

Linux 下基於socket的簡單網路聊天室

原文 經過親測除錯修改了部分內容 服務端程式 server.c include include 包含套接字函式庫 include include 包含af inet相關結構 include 包含af inet相關操作的函式 include include include include includ...

Linux下基於socket和多執行緒的聊天室小程式

要求 基於tcp編寫,乙個聊天室最多100人。客戶端 1 使用者需要登入,登入時只需要輸入乙個暱稱即可無需判斷暱稱是否重複 如果其他功能都ok考慮 2 使用者登入後連線伺服器端,進入聊天室 3 使用者可以輸入聊天資訊,也可以收到別人的聊天資訊。4 使用者可以用某個特殊單詞代表退出聊天室。額外功能 可...