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
sock.Listen
print("Listening on port: " + listen_port)
Var inp As String = ""
While inp <> "exit"
For Each connection As TCPSocket In sock.ActiveConnections
Print(connection.ReadAll)
Print("Send: ")
connection.Write(inp)
Print(connection.ReadAll)
connection.Flush
Next
inp = Input
Wend
Print("Closed")
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 127.0.0.1"
End If
Netstat output:
alexander@MacBookPro tcptest % netstat -an | grep 1337
tcp4 0 0 127.0.0.1.1337 127.0.0.1.59059 ESTABLISHED
tcp4 0 0 127.0.0.1.59059 127.0.0.1.1337 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 http://127.0.0.1:8090 in your webbrowser you’ll immediately note active connections along with remoteaddress and IP Hope this demo helps!
Hello,
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
SSocket.Listen
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)
conn.Write(inp)
conn.Flush
Next
Print("Send: ")
inp = Input
Wend
Print("Closed")
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 app.open 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!