Winsock control
Winsock control
Winsock control
Winsock control
Winsock control
Winsock control Winsock control Winsock control Winsock control Winsock control Winsock control Winsock control Winsock control
Winsock control Winsock control
Winsock control
Go Back  Xtreme Visual Basic Talk > > > Winsock control


Reply
 
Thread Tools Display Modes
  #1  
Old 06-03-2010, 06:59 PM
sonicdemonic sonicdemonic is offline
Junior Contributor
 
Join Date: Feb 2004
Location: Indiana
Posts: 261
Question Winsock control


OK, my program has a connect button that connects to a server on the other end. It connects fine. When you hit the connect button, that button hides and displays a disconnect button to manually disconnect from the server.
Here is my problem.
If i connect, disconnect, connect, disonnects and connect I get an error everytime. On the third connection attempt.
Now in Form Load I have
Code:
Load wsServer(1)

In cmdConnect I have
Code:
cmdConnect.Visible = False cmdDisconnect.Visible = True Form1.wsServer(1).Connect strServer, intPort
In cmdDisconnect I have
Code:
cmdConnect.Visible = True cmdDisconnect.Visible = False Form1.wsServer(1).Close


The error i get is
Code:
Run-time error '10093' WinsockInit should be called first.
from the cmdconnect code
Code:
Form1.wsServer(1).Connect strServer, intPort

I dont understand why I would be getting that error. I didnt unload the control.
Reply With Quote
  #2  
Old 06-03-2010, 09:39 PM
dilettante's Avatar
dilettanteWinsock control dilettante is offline
Underclocked lifestyle

Forum Leader
* Guru *
 
Join Date: Feb 2005
Location: Michigan, USA
Posts: 4,529
Default

When you Close a TCP connection only your end closes. Until the other end closes (and causes your Close event) the socket is still in use, and in the wrong state to reconnect. Sometimes if the timing is right you'll be ok, but you really should be setting your Connect button visible again in the Close event handler.

However with code like this you're leaving LocalPort set to whatever got allocated to it the first time you connect. Set LocalPort = 0 before calling Connect each time. This tells Winsock to allocate a free ephemeral port number, which is exactly what you want.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
Winsock control
Winsock control
Winsock control Winsock control
Winsock control
Winsock control
Winsock control Winsock control Winsock control Winsock control Winsock control Winsock control Winsock control
Winsock control
Winsock control
 
Winsock control
Winsock control
 
-->