Results 1 to 5 of 5

Thread: Winsock screws up ports

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2004
    Posts
    6

    Winsock screws up ports

    This problem is both sophisticated and stupid:

    I am writing mildly complex winsock apps for text messaging and checking files on an FTP server. Everything works fine under normal conditions, but occassionally something goes wrong: connection broken, program terminated without "saying goodbye" to the host, i-net cable is unplugged, etc. I can trap these exceptions easily. However, when I kill everything, close the wisocks, and try to start over I find that the port I was using is now tied up - I get an error message along the lines of "Address in use."
    So, does the winsock control simply not release the port if it's not closed properly? Is there some way to completely reset short of terminating the application? Any thoughts would be great...

    Roush

  2. #2
    Frenzied Member Jmacp's Avatar
    Join Date
    Jul 2003
    Location
    UK
    Posts
    1,959
    It takes a few mins to release the port as you said though i thought this was only with the API. There is an article on M$'s site about this, read it about 4 months ago. I'll have a look.

  3. #3
    Addicted Member
    Join Date
    Jun 2004
    Location
    USA
    Posts
    172
    You can prevent this. I figured out how. Make a timer called tmrPing, and put code similar in this to it:

    VB Code:
    1. Private Sub tmrPing_Timer()
    2. On Error Goto PingErr
    3. Dim pingData as String
    4. SCK.PeekData pingData
    5. Exit Sub
    6. PingErr:
    7. SCK.Close
    8. 'If this is the server then SCK.Listen
    9. End Sub

  4. #4
    Addicted Member
    Join Date
    Jun 2004
    Location
    USA
    Posts
    172
    Also, make sure to put that on both the client and the server. That way whoever disconnects you can have it still work. It works to where I can connect, disconnect, connect, disconnect, etc over and over as fast as I want.

  5. #5
    New Member
    Join Date
    Sep 2004
    Location
    Johannesburg, South Africa
    Posts
    6

    Thumbs up Great Help!!

    Just thought I'd say say Thanks xJake88x.

    I've been struggling with a similar problem all week.
    Thanks to you I've finally resolved it.

    All Hail the great Jake!!!

    Regards
    Neil

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