Re: [問題] 新手問socket
※ 引述《scdog (just do it)》之銘言:
: 我用java寫了一個tcp socket server
: 但是當client自行斷線時,server卻不知道client已經斷線
: 還一直丟封包給client(我程式寫成連線成功一直丟封包)
: 不知道socket有沒有function能夠判斷對方已經斷線
: 乾瞎!
有的
isConnected method or isClosed method
public boolean isConnected()
Returns the connection state of the socket.
Returns:
true if the socket successfuly connected to a server
Since:
1.4
public boolean isClosed()
Returns the closed state of the socket.
Returns:
true if the socket has been closed
Since:
1.4
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.116.96.181
討論串 (同標題文章)
本文引述了以下文章的的內容:
完整討論串 (本文為第 2 之 2 篇):