|
-
Apr 6th, 2009, 12:37 AM
#1
Thread Starter
Junior Member
detectc client disconnect
helo guys
i wrote a program (vb.net2005) for client- server communications using tcp/ip ,all are workin pretty well except one thing . when ever one new client is conected to server i ll display client ip and machine name on a grid. but i wont able to detect when a client is disconnected from a server
please provide some sample code for this
thx
-
Apr 6th, 2009, 12:41 PM
#2
Re: detectc client disconnect
You need to test whether the socket is still connected, then cleanup from there.
Do you know how to make custom events?
-
Apr 6th, 2009, 11:04 PM
#3
Thread Starter
Junior Member
Re: detectc client disconnect
no campion,
i dont no how to make custom events can u help me out
pls and also pls specify some sample codes
tahnx
-
Apr 7th, 2009, 06:01 AM
#4
Re: detectc client disconnect
I need a little more information, as well. Are you using an object to encapsulate the connections, or are they just being handled by a form?
Is each connection handled inside of its own class?
-
Apr 7th, 2009, 11:17 PM
#5
Thread Starter
Junior Member
Re: detectc client disconnect
yep it is just handled by a form . i had one client module and server module
to handle connections
-
Apr 8th, 2009, 06:53 PM
#6
Re: detectc client disconnect
This is how I handle disconnections. There's an event in there that fires off when it is sensed that the socket is no longer connected. However, since you have everything self-contained onto a form, what you need to do instead is ensure that your sockets are closed and that any references to the client no longer exists anywhere else in your project.
Code:
Try
BytesRead = _TcpServer.GetStream.EndRead(Ar)
_ServerMsgBuild = Encoding.GetEncoding(1252).GetString(_ServerBuffer, 0, BytesRead)
While _TcpServer.GetStream.DataAvailable
_ServerMsgBuild += Encoding.GetEncoding(1252).GetString(_ServerBuffer, 0, _
_TcpServer.GetStream.Read(_ServerBuffer, 0, _ServerBuffer.Length))
End While
Catch ex As Exception
RaiseEvent Disconnected()
Return
End Try
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|