Client / Server communication

Hello,

After watching the client / server example app, I tried to create two similar programs (one on Mac, the other on Windows)

Basically, my server app is always running and looking for a random client socket to connect, but I’m kinda lost in the code, and the code example is really confusing me (like, why is no port / ip specification ? It seems that the program just add random socket and that’s all)

I have some difficulties with TCPSocket / ServerSocket too, I don’t get the complete utility of these…

So here is my code for the server :

  Dim ClientSocket As TCPSocket
  
  ClientSocket = New TCPSocket
  
  ClientSocket.Port = 6500
  ClientSocket.Address = "0.0.0.0"
  ClientSocket.Listen
  
  Print "Waiting for client..."
  
  While Not ClientSocket.IsConnected
    If ClientSocket.LastErrorCode <> 0 Then
      Print "Nope, error"
      Exit
    End
  Wend
  
  If ClientSocket.IsConnected Then
    Print "Socket connected"
  Else 
    Print "Nope again"
  End If

I added the loop for always running the program, in the other case the command prompt is trigger at the launch but close after 1sec… And I have the same problem even with the loop.

The other part of my program is a ServerSocket with AddSocket event (but no code in there) and a TCPSocket with just a print for checking the connection.

On the other side I have my client app, but I think the problem is still in the server code…

Thanks by advance
Clment

The ServerSocket will listen. The client socket needs to connect.

Well, the first problem is : I can’t launch the server on Windows, cmd run off after 1sec, I’ve no idea why

And my client app got the socket who will try to connect on the same port, so… :frowning:

Well, the first thing is to use the debugger with the Server app to see why it’s quitting. I have no idea what example you’re using so i can’t really help. Use the debugger - it’s your friend.

Hum, the debugger doesn’t signal me anything.
I tried this on another Mac and the program doesn’t quit, but I got this error :

https://gyazo.com/4b33f8946f72fbc52375ac32d8115244

I’m using ServerSocketServerTest (and ServerSocketClientTest)

Put a breakpoint in the app.open event and see why it’s quitting. that’s what I mean by using the debugger.

Ok so here is my client app :

  Dim TCPSocket1 As TCPSocket
  Dim start, stop As Integer
  
  TCPSocket1 = New TCPSocket
  
  TCPSocket1.Port = 6500
  TCPSocket1.Address = "192.168.1.234"
  TCPSocket1.Connect
  
  Print "Trying to open connection on Server..."
  
  start = Ticks
  While Not TCPSocket1.IsConnected
    If TCPSocket1.LastErrorCode <> 0 then
      Print "Error : " + str(TCPSocket1.LastErrorCode)
      Exit
    End If
    TCPSocket1.Poll
  Wend
  
  stop = Ticks
  If TCPSocket1.IsConnected then
    Print "Socket connected in " + str(stop - start) + " ticks"
  Else
    Print "Failed to connect"
  End If
  
  
  TCPSocket1.Close
  Print "Socket closed"

When I run both programs the client get all wrong cases (with error 22 every time) and deny my socket. And the server doesn’t even open the port for the socket… (So maybe it’s why it doesn’t work but I rly don’t know how to fix this)

The Breakpoint instruction didn’t gave me more tips…

It looks like you’re using a console app. It would be a lot easier to use desktop apps, since you don’t have to service the sockets yourself. Also, you keep showing us the client side. That’s going to be useless until you get the server side running. Show us that code. If the server isn’t actively listening, the client will always fail to connect, which is what you’re seeing.