Results 1 to 6 of 6

Thread: TCP Server/Client - Disconnecting Sockets,

  1. #1

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    7

    TCP Server/Client - Disconnecting Sockets,

    removed
    Last edited by mrjoe12; Mar 23rd, 2010 at 02:11 PM.

  2. #2

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    7

    Re: TCP Server/Client - Disconnecting Sockets,

    bump

  3. #3

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    7

    Re: TCP Server/Client - Disconnecting Sockets,

    To be more specific on my problem, after researching around a little. I realise it's recieveing a null reference when looking to stream because the client is no longer there, however it's still looking for something.

    Now I tried to add a check like:
    vb Code:
    1. If networkStream.CanRead Then
    2.                                   Bla bla bla carry on then
    3.                         Else
    4.                                   Dont do it
    5.                         End If

    However it's still not working correctly, I dont understand why its still looking for a network stream. Is their any other way around this to avoid getting a system.nullreference object error when a client forcibly closes?

    Thanks

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: TCP Server/Client - Disconnecting Sockets,

    A crash is just an unhandled exception. There's nothing specifically wrong with exceptions, so just handle it and there's no crash. You might like to follow the CodeBank link in my signature and check out my Asynchronous TCP thread. You'll see that there are various places where pending asynchronous calls will cause exceptions to be thrown, so I just catch those exceptions and the app carries on.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    New Member
    Join Date
    Mar 2010
    Posts
    7

    Re: TCP Server/Client - Disconnecting Sockets,

    Quote Originally Posted by jmcilhinney View Post
    A crash is just an unhandled exception. There's nothing specifically wrong with exceptions, so just handle it and there's no crash. You might like to follow the CodeBank link in my signature and check out my Asynchronous TCP thread. You'll see that there are various places where pending asynchronous calls will cause exceptions to be thrown, so I just catch those exceptions and the app carries on.
    Thanks for the reply,
    As you can read in the doChat() part of the server there is a catch statement

    Catch ex As Exception
    MsgBox(ex.ToString)

    however it's obviously not working well. I looked over at how if bytes = 0 then disconnect user, however wouldn't you still crash at attempting to read the stream?

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: TCP Server/Client - Disconnecting Sockets,

    If you are catching an exception in one place and the app is still crashing then that exception is obviously being thrown elsewhere, so your Catch block is either in the wrong place or you need another. You need to catch exceptions in all places that they can reasonably be thrown. If you check out my code you'll see Catch blocks in various places.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width