man i've been beating my head over this for 2 days now. heres what i have, a pc sitting at 192.168.2.101 is listening for a connection. when a use the b4a program client2 everything works fine. with the program client5 i'm trying to move the code from client2 into a service. everything seems right to me. but what happens its that the connection is made and the server is ready to accept the incoming message but nothing happens. nether program locks, they just sit there. i've included both the working client2 and the nonworking client5. but heres then code for the heart of client5, some of you gurus might just be able to look at this and see the problem.
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Socket1 As Socket
Dim AStreams As AsyncStreams
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
Socket1.Initialize("Socket1")
Socket1.Connect("192.168.2.101", 8888, 10000)
If AStreams.IsInitialized = False Then Return
Dim Bytebuffer() As Byte
Dim data As String
data = "Diod: Home Router in Range" & CRLF
Bytebuffer = data.GetBytes("UTF8")
AStreams.Write(Bytebuffer)
End Sub
Sub Service_Destroy
AStreams.Close
Socket1.Close
End Sub
Sub Socket1_Connected (Successful As Boolean)
If Successful Then
ToastMessageShow("Connected!", False)
AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")
Else
ToastMessageShow("Error while connecting!", False)
End If
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
ToastMessageShow(msg, False)
Log("Received: " & msg & " from the server")
End Sub
Sub AStreams_Error
ToastMessageShow(LastException.Message, True)
End Sub
Sub Activity_Pause(UserClosed As Boolean)
If UserClosed Then
' Log("closing")
AStreams.Close
Socket1.Close
End If
End Sub
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim Socket1 As Socket
Dim AStreams As AsyncStreams
End Sub
Sub Service_Create
End Sub
Sub Service_Start (StartingIntent As Intent)
Socket1.Initialize("Socket1")
Socket1.Connect("192.168.2.101", 8888, 10000)
If AStreams.IsInitialized = False Then Return
Dim Bytebuffer() As Byte
Dim data As String
data = "Diod: Home Router in Range" & CRLF
Bytebuffer = data.GetBytes("UTF8")
AStreams.Write(Bytebuffer)
End Sub
Sub Service_Destroy
AStreams.Close
Socket1.Close
End Sub
Sub Socket1_Connected (Successful As Boolean)
If Successful Then
ToastMessageShow("Connected!", False)
AStreams.Initialize(Socket1.InputStream, Socket1.OutputStream, "AStreams")
Else
ToastMessageShow("Error while connecting!", False)
End If
End Sub
Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
ToastMessageShow(msg, False)
Log("Received: " & msg & " from the server")
End Sub
Sub AStreams_Error
ToastMessageShow(LastException.Message, True)
End Sub
Sub Activity_Pause(UserClosed As Boolean)
If UserClosed Then
' Log("closing")
AStreams.Close
Socket1.Close
End If
End Sub