Winsock Problem 
Author Message
 Winsock Problem

I have got a client/server application where the client opens a winsock
tcp/ip connection, writes data to the winsock and then closes the
connection. This happens everytime the client wants to send data to the
server.

The problem is that every time the client closes the TCP connection,
the  winsock in the server changes the listening port. Is there any way
of keeping the listening port constant so that the client always
connects on the same port?

I have tried to set the winsock LocalPort property to a fixed port e.g.
2749 but when i do this the client fails to connect again after the
first successful connect. I get an error message saying that the winsock
is in the wrong state.

Thanks for your help.




Tue, 09 Apr 2002 03:00:00 GMT  
 Winsock Problem
On server: Set Localport = wanted number just before calling the listen
method.
On client: set remoteport = wanted number and localport = zero just
before calling the connect method.

--
Regards,
Mikkel H. Andersen



Tue, 09 Apr 2002 03:00:00 GMT  
 Winsock Problem
Try putting this code in both the client and the server. It sounds
like the server isn't fully closing.

Private Sub Winsock1_Close()
If Winsock1.State <> 0 Then Winsock1.Close
End Sub

Isaac

On Fri, 22 Oct 1999 10:40:32 +0100, Shamji Patel

Quote:

>I have got a client/server application where the client opens a winsock
>tcp/ip connection, writes data to the winsock and then closes the
>connection. This happens everytime the client wants to send data to the
>server.

>The problem is that every time the client closes the TCP connection,
>the  winsock in the server changes the listening port. Is there any way
>of keeping the listening port constant so that the client always
>connects on the same port?

>I have tried to set the winsock LocalPort property to a fixed port e.g.
>2749 but when i do this the client fails to connect again after the
>first successful connect. I get an error message saying that the winsock
>is in the wrong state.

>Thanks for your help.





Tue, 09 Apr 2002 03:00:00 GMT  
 Winsock Problem

I have tried to set the winsock LocalPort property to a fixed port e.g.
2749 but when i do this the client fails to connect again after the
first successful connect. I get an error message saying that the winsock
is in the wrong state.

After you close your winsock connection, LocalPort changes (if I remember
correctly), so you need to reset it before listening again...(otherwise its
pretty darn random - check it with a debug.print statement)

'Server Side

Private Sub Form_Load()
    ServerIPInfoBox.Text = ServerSock.LocalIP
    ServerConnectFromBox.Text = "Waiting"
    ServerSock.LocalPort = 29
    ServerSock.Listen
End Sub

This also required me to include a reset button on the server, my
implementation kinda goes against CW here...

Private Sub cmdServerReset_Click()
    ServerSock.Close
    ServerSock.LocalPort = 29
    ServerSock.Listen
End Sub

Private Sub ServerSock_Close()
    cmdServerReset_Click
End Sub

The client should be able to connect every time to port 29 (telnet port?)



Tue, 09 Apr 2002 03:00:00 GMT  
 Winsock Problem
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Depending on the design of your Client/Server, the server should be
able to open the reset the port to listen mode after a connection. Or
better, revise your SERVER programs to accept multiple connection.  
Here are the steps

SERVER
Initialization:
1.  Create a new socket and select a port to listen to.
2.  Wait for a connect event.

When connection is detected:
1.  Create a new socket and accept the connection.
2.  Proceed with CLIENT/SERVER conversation.

The above example is the ideal client/server setup.  Which means, the
port where the SERVER is listening is NEVER closed, and all
connections to it is ACCEPTED in a different port.

Hope this helps,

Rey Arson II
Sistema Pilipinas MCMXCIII
Arson Engineering 2000

Quote:

>I have got a client/server application where the client opens a
winsock
>tcp/ip connection, writes data to the winsock and then closes the
>connection. This happens everytime the client wants to send data to
the
>server.

>The problem is that every time the client closes the TCP connection,
>the  winsock in the server changes the listening port. Is there any
way
>of keeping the listening port constant so that the client always
>connects on the same port?

>I have tried to set the winsock LocalPort property to a fixed port
e.g.
>2749 but when i do this the client fails to connect again after the
>first successful connect. I get an error message saying that the
winsock
>is in the wrong state.

>Thanks for your help.



-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBOBmtO0kQgOtuDKxxEQJgIwCguZcriLNIpBU5N/Z+FGVvz2E0zoAAoIBt
iuxXIlPgF8Kb4BvseHgclhXd
=/eJU
-----END PGP SIGNATURE-----

 Sent via Deja.com http://www.deja.com/
 Before you buy.



Wed, 17 Apr 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. winsock problem sending large strings (winsock.senddata)

2. Winsock Problem

3. .NET Socket vs VB6 Winsock problem!

4. winsock problems

5. Simple WINSOCK Problem

6. Simple Winsock Problem

7. Winsock Problems

8. VB5: winsock problem

9. Visual Basic 6 Winsock Problem

10. VB6 Winsock Problem

11. Winsock Problem

12. odd winsock problem

 

 
Powered by phpBB® Forum Software