/**
* created by liwei on 2016/7/17.
* 模擬乙個簡單的聊天室程式
* 通過多執行緒改進剛開的聊天程式,這樣我們就可以實現在乙個視窗傳送和接收資料了
*/public
class
mainchatroom
}
傳送端線程:
public
class
sendthread
implements
runnable
@override
public
void
run()
byte bys = line.getbytes();
datagrampacket dp =
new datagrampacket(bys,bys.length, inetaddress.getbyname("192.168.100.112"),10086);
// 傳送資料
datagramsocket.send(dp);
}// 釋放資源
datagramsocket.close();
} catch (ioexception e)
}}
接收端執行緒:
public
class
receivethread
implements
runnable
@override
public
void
run()
} catch (ioexception e)
// 接收端,不要關閉 socket
}}
Python通過多執行緒實現 非同步
import threading,time defthead num print 執行緒 s開始執行 num time.sleep 5 print 執行緒 s執行完畢 num defmain print 主方法開始執行 poll 執行緒池for i in range 1,3 thead one th...
python DLib實時性不夠,通過多執行緒來解決
created at 2017 11 27 updated at 2018 09 06 author coneypo dlib blog github import dlib import time,threading import queue from skimage import io impo...
Socket 多執行緒
服務端 include include pragma comment lib,ws2 32 include void sendfuction socket sockconn void recvfunction socket sockclient void main if lobyte wsadata...