Server Socket Networking Issues.

I’m using a Server Socket in my app on a Windows 10 Pro machine to allow about 35 clients to connect. The clients will connect and send a small amount of data and disconnect every few minutes throughout the day. After a few days of use the clients are no longer able to connect to the app with the server socket. The clients also try to ping the IP address of the computer and the logs show they can’t ping the IP when this issue happens. Once the computer is restarted everything starts connecting normally. This leads me to believe it is a problem on the Windows OS level but I can’t find any specific proof of this online.

This is the code I use to initialize the server socket.

SckSrv = New SckListen SckSrv.Port = Val(gstrPort) SckSrv.MaximumSocketsConnected = gintServerMax SckSrv.MinimumSocketsAvailable = gintServerMin SckSrv.Listen

What are the best values for MaximumSocketsConnected and MinimumSocketsAvailable in this type of scenario? I am currently setting minimum to 50.

I would appreciate any advice that might help resolve this issue. Thanks.

Are you saving the sockets in any way on the Server? Can you tell if the sockets on the server are getting a 102 (disconnect) error?

I’m not saving the sockets. I was getting the 102 disconnect message a lot during testing so I stopped logging it.

Socket error event code:

[code]dim intErr As integer
dim strErr As string

intErr = me.LastErrorCode

Select Case intErr
Case 0
strErr = “NoError”
Case 100
strErr = “OpenDriverError”
Case 102
strErr=“LostConnection”
Case 103
strErr= “NameResolutionError”
Case 105
strErr = “AddressInUseError”
Case 106
strErr = “InvalidStateError”
Case 107
strErr = “InvalidPortError”
Case 108
strErr = “OutOfMemoryError”
End Select

if intErr <> 102 then
LogMsg ("SckServer Msg: " + "Code " + str(intErr) + " : " + strErr)
end[/code]

I’ve observed the problem machine in the resource monitor while it’s in use and the connections from the client machines don’t seem to be excessive. They turn grey and go away in the resource monitor after about a minute. I didn’t observe multiple connections to the same IP.

What should I be setting the MaximumSocketsConnected to? I can clearly see 50+10 connections made on app open if I set MinimumSocketsAvailable to 50. Could I be causing a network crash in the Windows OS by setting the MaximumSocketsConnected too high?

Keep in mind MinimumSocketsAvailable is NOT the maximum number of sockets. It’s the smallest number of sockets available in the server’s pool of socket connections. If the ServerSocket falls below this number, it will call the AddSocket event to replenish its supply of sockets.

What are doing in the AddSocket event?

[quote=402786:@Bob Keeney]Keep in mind MinimumSocketsAvailable is NOT the maximum number of sockets. It’s the smallest number of sockets available in the server’s pool of socket connections. If the ServerSocket falls below this number, it will call the AddSocket event to replenish its supply of sockets.

What are doing in the AddSocket event?[/quote]
Right. I am setting minimum to 50 and maximum has been set as high as 1000 at one point for testing.

TCPSocket AddSocket:

[code]dim sckTCP As new SckServer

intConnCnt = intConnCnt + 1

If me.IsListening Then
LogMsg “Socket:(” + str(intConnCnt) + ") " + "is now listening on port " + gstrPort

’ Just added this for testing today
LogMsg “Total Active Connections:(” + str(me.ActiveConnections.Ubound) + “)”
Return sckTCP
End

intConnCnt = 0[/code]

SckServer parses the messages from the clients and sends a response. I don’t close the connection manually from SckServer. Both are sub classed sockets.

Is there some kind of known limitation before the Windows OS refuses to accept any more connections? I can’t understand what is causing this issue because as I said in the first post it’s not just an issue with my app, the clients cannot ping the IP of the computer when this happens until the computer running the app is restarted.

@Bob Keeney thanks for your help.

Are you sure the clients are actually closing the TCP connection?

It’s been a long time since I’ve messed with ServerSocket so I’m kind of grasping at straws. When I get into something like I create very simplified projects and see if I can replicate the issue. Usually it’s because I’ve made a silly assumption on how a class works that gets revealed in the simple project.

[quote=402796:@Bob Keeney]Are you sure the clients are actually closing the TCP connection?

It’s been a long time since I’ve messed with ServerSocket so I’m kind of grasping at straws. When I get into something like I create very simplified projects and see if I can replicate the issue. Usually it’s because I’ve made a silly assumption on how a class works that gets revealed in the simple project.[/quote]

Looking over the client code I am not manually closing the socket from the client. I think I’ll try some tests to verify things are working as they should be as it’s been awhile since I wrote this. It’s going to be impossible to test it under the same stress though. Thanks again for your help.

MS don’t like you using a desktop computer as a server and limit the number of inbound concurrent connections. Try running your app on a server version of Windows. You can download a trial copy of 2016 with a 6 month license from MS and can renew the license twice to give 18mnths of free use.

I have read this Wayne and I was hoping someone would bring this up in here. The information online is so vague about what these connections are and what exactly happens. There is nothing in the error log when this happens, it’s just like the networking on the OS completely shuts down until the computer is restarted.

I wonder if a Xojo Server Socket hosting connections to 30 plus computers over time would trigger some kind of MS limitation for a desktop computer OS?

Also I should mention that there is another server program I didn’t write not written in Xojo that the same 30 plus clients are connecting to on the same desktop computer.

From the EULA

“Device connections. You may allow up to 20 other devices to access the software installed on the licensed device for the purpose of using the following software features: file services, print services, Internet information services, and Internet connection sharing and telephony services on the licensed device. You may allow any number of devices to access the software on the licensed device to synchronize data between devices. This section does not mean, however, that you have the right to install the software, or use the primary function of the software (other than the features listed in this section), on any of these other devices.”

[quote=402817:@Wayne Golding]From the EULA

“Device connections. You may allow up to 20 other devices to access the software installed on the licensed device for the purpose of using the following software features: file services, print services, Internet information services, and Internet connection sharing and telephony services on the licensed device. You may allow any number of devices to access the software on the licensed device to synchronize data between devices. This section does not mean, however, that you have the right to install the software, or use the primary function of the software (other than the features listed in this section), on any of these other devices.”[/quote]

Right, I have seen this and I have also read that if you violate this the OS can stop responding.

I wonder how many Windows 10 clients can connect to a Xojo Server Socket at the same time before MS thinks you have exceeded this? It would be nice if MS wrote something to the system log warning you.

Thanks Wayne for all your insight.

In all my years running game servers and other things with hundreds of connected users coming and going 24/7 I’ve never had connection limits either running desktop or server editions during general use. Connection limits on named services (file, print etc), sure, but not a little tcp listener running on the computer, this would cause so many issues.

Do you have any idea how many connections causes your issue? Is it always similar values? After approximately X connections it stops because it sounds like you’re not releasing your connections correctly and you’re hitting the port limit in windows.

35 connections every 10 minutes is 5040 per day, the pool is limited to 16384 in windows 10 so you’ll get through that pool in just over 3 days at which point you’ll have issues like those you’re mentioning.

[quote=402846:@]In all my years running game servers and other things with hundreds of connected users coming and going 24/7 I’ve never had connection limits either running desktop or server editions during general use. Connection limits on named services (file, print etc), sure, but not a little tcp listener running on the computer, this would cause so many issues.

Do you have any idea how many connections causes your issue? Is it always similar values? After approximately X connections it stops because it sounds like you’re not releasing your connections correctly and you’re hitting the port limit in windows.

35 connections every 10 minutes is 5040 per day, the pool is limited to 16384 in windows 10 so you’ll get through that pool in just over 3 days at which point you’ll have issues like those you’re mentioning.[/quote]

Thanks for the response Julian.

It seems like there would be some kind of error in the system log if that kind of event occurred but maybe not. I’ve watched the network activity in the resource monitor and it looks like the connections are being closed after about a minute they turn grey and then go away.

In your opinion what is the best way to release the connection? I’ve read many different opinions on this. If the client app is initiating the connection to the server app and then waiting for a response should you manually close the connection on the client side once the response has been received or on the server side once the response has been sent?

If the client initiated the connection it should be the one to close it. However, the server side needs to make sure it’s not retaining a reference to socket somehow so if you know the socket on the server side is getting a 102 error (disconnect) you must make sure that the reference to that socket isn’t retained so it can be reused.

I think you could simulate this relatively easily. Just set up a sample server project that is a simple 'repeat the message back to me" server socket. Then make a client that does this really fast. Using a simple counter send a message “Send Message 1”. Once it receives the response you close the socket. Then send message 2 and so on and see if you get it to lock up. In the ideal world you should be able to do this very fast, all day long, and never have blip. But if you’re having problems it will demonstrate itself and you might be able to see what it is.

FWIW, I do this all the time to verify I’m not going crazy though my family keeps trying to tell that it’s not proof.

@Bob Keeney

Sounds like a solid plan. Thanks for all the help. :slight_smile:

Of course, it if happens with your sample apps then it’s easy to share and we can dissect it and help more.