各位大虾,网络断开连接问题(socket),大家请看。。。。 ( 积分: 18 )

  • 主题发起人 主题发起人 slb302
  • 开始时间 开始时间
S

slb302

Unregistered / Unconfirmed
GUEST, unregistred user!
,以下是服务器端的监听
Public Sub establistsocket(ByVal state As Object)
Dim StrName As String
Dim StrIP As String
Dim Address() As System.Net.IPAddress
While run
listener = New socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
StrName = Dns.GetHostName()
Address = Dns.GetHostByName(StrName).AddressList
StrIP = Address(0).ToString
Dim serveradd As IPAddress = Dns.Resolve(StrIP).AddressList(0)
Dim enpoint As New IPEndPoint(serveradd, 1101) '设置端口
listener.Bind(enpoint) '绑定本机的IP地址
listener.Listen(0) '侦听
socket(socketCount) = listener.Accept '接收连接请求,并实例化一个Socket对象
listener.Close() '关闭侦听
socketCount = socketCount + 1
End While
End Sub
请问当我和很多客户都建立连接之后,当其中有一个和多个客户端断开连接之后,我在服务器端怎么判断哪个客户端已经断开连接
 
,以下是服务器端的监听
Public Sub establistsocket(ByVal state As Object)
Dim StrName As String
Dim StrIP As String
Dim Address() As System.Net.IPAddress
While run
listener = New socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
StrName = Dns.GetHostName()
Address = Dns.GetHostByName(StrName).AddressList
StrIP = Address(0).ToString
Dim serveradd As IPAddress = Dns.Resolve(StrIP).AddressList(0)
Dim enpoint As New IPEndPoint(serveradd, 1101) '设置端口
listener.Bind(enpoint) '绑定本机的IP地址
listener.Listen(0) '侦听
socket(socketCount) = listener.Accept '接收连接请求,并实例化一个Socket对象
listener.Close() '关闭侦听
socketCount = socketCount + 1
End While
End Sub
请问当我和很多客户都建立连接之后,当其中有一个和多个客户端断开连接之后,我在服务器端怎么判断哪个客户端已经断开连接
 
加一个timer,就可以经常的刷新列表了
 
还有啊,就是客户端断开连接以后,服务器端建立的socket(i)实例没有释放掉,
我这边怎么样知道客户端已经不在线了?
知道了,我就把这个对象释放掉的!
 
怎么知道客户端已经断开连接?
 
www.51merit.com
上有socket 专区
 
看不到源码阿?
各位大虾,帮帮我啊
 
怎么样及时知道客户端已经断开连接,就像qq一样,怎么知道对方下线
 
VB不清楚;
DELPHI异常断开有ClientError事件,根据errcode可判断:
procedure Tfrmmain.ServerSocket1ClientError(Sender: TObject;
Socket: TCustomWinSocket;
ErrorEvent: TErrorEvent;
var ErrorCode: Integer);
var
i:word;
temstr:string;
begin
temstr:='ErrorCode:'+IntToStr(ErrorCode);
case ErrorEvent of
eeSend: if dispError then
ShowMessage(temstr+'WINSOCK,'写错误');
eeReceive: if dispError then
ShowMessage(temstr+'WINSOCK,'读错误');
eeConnect: if dispError then
ShowMessage(temstr+'WINSOCK,'客户端接收不完整');
eeAccept: if dispError then
ShowMessage(temstr+'WINSOCK,'接收错误');
eeGeneral: if dispError then
ShowMessage(temstr+'WINSOCK,'其他错误');
eeDisconnect://
begin
LinkCount:=ServerSocket1.Socket.ActiveConnections;
temstr:='00000'+IntToStr(Socket.SocketHandle);
SocStr:='socket:'+copy(temstr,Length(temstr)-5,6);
for i:=0 to LinkCount-1do
if (LonLines.Items.Count>0) and (pos(SocStr,LonLines.Items)<>0) then
begin
LonLines.Items.Delete(i);
if LinkCount>0 then
Dec(LinkCount);
Break;
end;
if dispError then
Showmessage('异常断线,当前连接数:'+InttoStr(LinkCount));
end;
end;
ErrorCode:=0;
end;
 
加入心跳包
 
我用的是vb.net 里面好像没有这种事件啊,不知道怎么做啊高手们教我怎么做啊
 
后退
顶部