VB6: Winsock Address in use

Posted on 2003-03-28
Medium Priority
Last Modified: 2013-11-13
I am making a 2-way file transfer program, with 2 winsocks, one for files and one for information. The problem is after the client connects, I invoke the close method for both, but if i try to connect again, it doesn't work. But heres the weird thing: If i step through the program, it works! But with normal F5 operation, i always get that error. Is there some way to close the port that I should know? If you need my code I can post it.
Question by:rlbond
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions

Expert Comment

ID: 8225514
This is common.  I have incremented the port to avoid this.  Set up a port variable and each time you open the port increment it and use that variable as port number.  You don't need a lot of numbers. Say you start with 0, Take it to say, 5, then start over at 0 again.  This has to do with the way Windows reclaims the resources involved with allocating ports.  It seems to do this when it gets around to it rather than when you close the port...

Accepted Solution

PNJ earned 500 total points
ID: 8225644
It's all to do with Windows hanging onto the port for 5 (or 10?) minutes and then it releases it. The recommendation is for your CLIENT always to use Port 0 which tells Winsock to choose the next available port:

   frmMain.sckClient.LocalPort = 0 ' Force random choice of LOCAL socket.
   frmMain.sckClient.Connect 123.456.789.111, 5000

However, you SERVER should always listen on your selected port:

   frmMain.sckServer(0).LocalPort = 5000

(extracts from my Client/Server programs)

Author Comment

ID: 8238996
Ok that worked

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question