I made a mistake in my previous post , the socket and all the subs are located in a static code module (not in a service) .
my subs are really basic for the moment (just for testing) :
B4X:
Dim Socket1 As Socket
Dim SOCKETHOST As String
Dim SOCKETPORT As Int
SOCKETHOST = "myserver.com"
SOCKETPORT = 1234
Sub connectToSocket () '
Socket1.Initialize("Socket1")
Socket1.Connect(SOCKETHOST, SOCKETPORT, 200)
End Sub
Sub Socket1_Connected (Successful As Boolean)
Try
If Successful = False Then
Msgbox("Error Connecting to server","OK")
Else
Msgbox("Connected to server","OK")
End If
Catch
End Try
End Sub
the connectToSocket method is called from the main activity_create
I've tried to put the previous code in a service module but the problem is that i can't call the connectToSocket method from the service module.
serviceModule.connectToSocket doesn't work
I've just replied in your other thread. Please do not duplicate questions.
But to be clear, service module's can handle events whereas code modules can't. Code modules are really only for performing business logic, crunching numbers and providing a result etc. No view's and no events.