Login  
Search All Forums
Dart Home | PowerTCP Sockets for .NET | Custom Development Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
AuthorForum: PowerTCP Sockets for .NET (Secure and Standard)
Topic: Catch Disconnect from Server
LITHIA

From: England, United Kingdom
Posts: 3
Member Since: 05/19/04
posted May 19, 2004 10:47 AM

Hi,

I enquired about this on VBForums, and a nice person told me to ask here as you have excellent technical support ;)

Here's the post:
-------------------
Hi,
I just got PowerTCP Sockets and it seems to be very good.

However I am really stuck. I can't see anything about disconnecting when using the server control. Does anyone know how you can catch when someone disconnects from the server?

Also, when they do disconnect, how would you clear it from the array Connections? When I disconnect from the server, it doesnt change the ammount of users connected as it just counts how many entries there are in the array...
-------------------

So I would really appreciate any help in this! I looked through the samples, but I don't exactly understand your method of:
-------------------
Finally
      ' Add to status box
      msg = "Client [" + id + "] has disconnected"
      BeginInvoke(New UiDelegate(AddressOf AppendStatus), StringToObjectArray(msg))

      ' Remove connection from listbox
      BeginInvoke(New UiDelegate(AddressOf RemoveConnection), StringToObjectArray(id))
    End Try
-------------------

I have never come across "Finally" before, but I am guessing its executed at the end of the "Execute"

Is there an easier way, and precise way, to catch when people disconnect? I would have thought there was a section on this, like there is "ActiveChanged" and "Connection" and "Disposed" eg,
Private Sub server1_Connection(ByVal sender As System.Object, ByVal e As ConnectionEventArgs) Handles server1.Connection

A lot like Winsock has a lot, including "OnError" which was really handy and made it easy to manipulate.

I also mentioned about the ammount of users, whats the easiest way to get rid of the user from the array when they disconnect? I only want...
Server1.Connections.Count to return the ammount of users CURRENTLY connected, not overall of how many are have been connected. Is there a specific feature for this, rather than counting the entries in the array, as I can't say this is very handy without removing them from it after they disconnect.

Thanks very much for the help, sorry if this post is really long but I really want to make sure I'm clear!
THANKS!!! :)
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted May 19, 2004 11:11 AM

"finally" is used in a "try ... catch" block. The code in the Try block is attempted first. If a line fails then the "catch" block is entered. The "finally" block is run at the end, regardless of error.

This would be the equivalent of:

On Error goto OnError
' This is the try section
goto Done

OnError:
' This is the catch section
Done:
' This is the finally section

You know when people disconnect if the "catch" section is entered.

Please take another look at the samples. They are really the best way to learn how things work.

LITHIA

From: England, United Kingdom
Posts: 3
Member Since: 05/19/04
posted May 20, 2004 4:07 AM

ah so if there is an error, you regard it as the user has disconnected?
interesting way of doing it...
just out of curiosity, why isnt there a disconnect event like in winsock? i would have expected that to be a lot easier, but im not questioning your method, ill have a go at it :)
thanks for the help, I hope I can get it to work, im kind of inexperienced in this area.
Tony Priest



From: Utica, NY USA
Posts: 8466
Member Since: 04/11/00
posted May 20, 2004 11:41 AM

I think I may have confused you with some wrong advice. Let's take a look at the EchoServer sample. The entire session consists of a loop that receives and echoes until the connection closes.

In this scenario, you now that the client closed when the loop is exited.

Does that help?
LITHIA

From: England, United Kingdom
Posts: 3
Member Since: 05/19/04
posted May 21, 2004 11:19 AM

i think i understand... thanks, ill try it out on my app right now and tell you how it goes
Reply | PowerTCP Sockets for .NET (Secure and Standard) Topics | Forums   
This site is powered by PowerTCP WebServer Tool PowerTCP WebServer for ActiveX