C Socket多執行緒TCP短連線 模擬叫號

2021-10-06 11:57:57 字數 876 閱讀 1391

以下demo為開發中常用的tcp連線方式,服務端不需要啟動,實時監聽客戶端是否有資料傳輸,如果有會多執行緒監測叫號,而客戶端只需要把叫號資訊包裝進流,tcp方式傳輸即可

demo:1、服務端**如下:

public partial class shortserverform : form

private thread rdthread = null;//定義接收資料的執行緒

private tcplistener tcplistener = null;//通過tcpip進行資料的接收

private spvoice voice = new speechlib.spvoice();

private void shortserverform_load(object sender, eventargs e)

catch (exception ex)

}private void rd()}}

catch (exception ex)}}

}

2、客戶端:

輸入叫號的內容,即可請求,請求**如下:

/// /// 設定預設請求本地ip  8800埠

///

///

///

private void btnqq_click(object sender, eventargs e)

else

}catch (exception ex)

}

此方法為短連線形式,不會過多的占用資源,開發過程安全。

C Socket多執行緒程式設計(一)

csharp view plain copy 實現伺服器端 建立client類 using system using system.collections.generic using system.linq using system.text namespace chartserver endreg...

TCP 多執行緒 (python)

author han zhang date 2018 12 23 10 21 file server.py ide pycharm import socket,threading def c thread s client,addr print addr,成功連線 列印連線者位址資訊 while t...

TCP多執行緒聊天

1 from socket import 2from threading import thread 3 sockets 4def main 5 建立server socket套接字物件 6 server socket socket af inet,sock stream 7 繫結埠 8 serve...