ServerSocket.ActiveConnections empty (even though client application is connected)?!

Hello friends,

I am currently trying to use ServerSocket.ActiveConnections. So far I understand that .ActiveConnections will return an Array of TCPSockets which are already connected. So I don’t have to use .Connect again for the TCPSockets that will be returned from .ActiveConnections. Am I right?

var sock As Server =  New Server // Server is ServerSocket

sock.Port = listen_port.ToInteger

print("Listening on port: " + listen_port)

Var inp As String = ""

While inp <> "exit" 
  For Each connection As TCPSocket In sock.ActiveConnections
    Print("Send: ")
  inp = Input


The problem is that .ActiveConnections is completely empty!

I checked the connection and it should be fine, Client and Server application are connected so far.
I know that because I check in my Client application the .isConnected property of TCPSocket and it returns True.

If sock.IsConnected Then // sock is TCPSocket
  Print("Connected to " + sock.RemoteAddress) // Prints "Connected to"
End If

Netstat output:

alexander@MacBookPro tcptest % netstat -an | grep 1337
tcp4       0      0        ESTABLISHED
tcp4       0      0         ESTABLISHED
tcp4       0      0  *.1337                 *.*                    LISTEN

I see the issue. You’re not returning any sockets in the ServerSocket AddSocket event so the connections are being made, but as individual connections. Please see attached demo. If you visit in your webbrowser you’ll immediately note active connections along with remoteaddress and IP :slight_smile: Hope this demo helps!


fyi, it’s a console application.

I already had the following code in the AddSocket event of Server class:

Var socket As Client = New Client(num)
num = num + 1
Print("Socket added")

return socket

It’s not even printing “Socket added”. The event is not firing.

I have added a property to App called SSocket as Type Server.

This is the Run event of App (as of now):

Var listen_port As String = "1337"

SSocket = New Server
SSocket.Port = listen_port.ToInteger

Print("Listening on port: " + listen_port)

Print("Send: ")

Var inp As String = Input

While inp <> "exit" 
  For Each connection As TCPSocket In SSocket.ActiveConnections
    Var conn As Client = Client(connection)
  Print("Send: ")
  inp = Input


This is exactly my problem. And it looks like as if the user wasn’t able to solve his problem.

**In this demo - the desktop client is only a client - the server was ripped out of it.
**For the console app - I literally pasted the “TheServer” folder into the console app, changed the messageboxes to “print” (so it would show in the console) and fired up the server in the event.

See if this demo helps. This is how our blockchain software works - except all nodes act as a client and server in console mode interacting with one-another in peer-to-peer based fashion.

1 Like

This helped a lot! Thank you!