socket.Connect causes interface lockup while connecting?

I’m using Xojo to test a TCP server utility. The Xojo project, at the moment, is relatively simple; a form that lets me enter a port and an address, click connect, then it sends strings to the server which echos back a response that is displayed in another textbox.

If the server isn’t running when I click connect, the interface locks up while I assume it’s waiting to time out…it’s running on the Mac, so all I have in the Xojo window is a spinning beachball.

Is there an idiomatic way to avoid this, so I could quit the connection process if necessary?

The connect button has this in the Action handler:

[code]Dim port as Integer

// Status update
lblStatusText.Value = “Initializing socket”

App.socket = new TCPSocket

// Status update
lblStatusText.Value = “Setting address and port”
App.socket.Address = ComboBoxConServer.Value
port = Val(ComboBoxConPort.Value)
App.socket.Port = port

// Status update
lblStatusText.Value = "Server: " + ComboBoxConServer.Value + ", Port: " + ComboBoxConPort.Value

// Connect the socket
App.socket.Connect

// while the socket isn’t connected
While Not App. socket.IsConnected

// Error check
If App.socket.LastErrorCode <> 0 Then
lblStatusText.Value = "Error: " + Str(App.socket.LastErrorCode)
End

// poll the socket to let it do its thing
App.socket.Poll
// if an error occurs, the Error event will fire
Wend

// Status update
lblStatusText.Value = “Connected”

// Open the debugging window
winTest.Visible = True[/code]

It is the loop that’s causing the issue. I would recommend you create a class where the super is TCPSocket and implement the Connected Event to update your label. This will allow the event loop to run and you shouldn’t see the beach-ball while polling.

I think I got it working, thanks to your advice!
(I’m very new to Xojo, trying to learn it after a long hiatus and I’m most familiar with Go, which seems to be an entirely different beast from event-driven OOP like Xojo…)

For others who may have this question (or if you see this and have tips on a better way to do this), I added a class to the project from the Library. I selected the class, and in the Inspector I named it AppSocket and selected TCPSocket as the Super.

Right clicked the class (now called AppSocket) in the left viewer panel and added two event handlers; “Connected” and “Error”.

Connected consists of:

[code]// Status update
WindowMain.lblStatusText.Value = “Connected”

// Open the debugging window
winTest.Visible = True[/code]

Error consists of:

WindowMain.lblStatusText.Value = "Error: " + Str(App.socket.LastErrorCode)

That leaves the previous handler code, which is the Action for a connect button I posted previously, to now consist of:

[code]Dim port as Integer

// Status update
lblStatusText.Value = “Initializing socket”

App.socket = new AppSocket

// Status update
lblStatusText.Value = “Setting address and port”
App.socket.Address = ComboBoxConServer.Value
port = Val(ComboBoxConPort.Value)
App.socket.Port = port

// Status update
lblStatusText.Value = "Server: " + ComboBoxConServer.Value + ", Port: " + ComboBoxConPort.Value

// Connect the socket
App.socket.Connect
[/code]

Now if the server isn’t running when I click Connect, the status text label throws an Error 22 almost immediately!