Use the correct address in your local network if that net/subnet does not match your configuration.
Are you trying to run a b4j-code in android?
Hi Don, whose address in the network you are referring to? I have experience of using AsyncStreams/TCP-IP on this wifi network to connect the PC and Android. There shouldn't be any problem for Websockets.
No I am not running B4J code in B4a. B4a is the Websockets Client.
The Server code in that example is just this much (unchanged by me):
[CODE lang="b4x" title="B4J Code in B4J IDE"]'Non-UI application (console / server application)
#Region Project Attributes
#CommandLineArgs:
#MergeLibraries: True
#End Region
Sub Process_Globals
Public srvr As Server
End Sub
Sub AppStart (Args() As String)
srvr.Initialize("")
srvr.Port = 51042
srvr.AddWebSocket("/ws", "B4A")
srvr.Start
StartMessageLoop
End Sub[/CODE]
B4a Code for reference from that example (unchanged except for the ip address):
[CODE lang="b4x" title="B4A Example Code for Websockets Client" highlight="17"]#Region Project Attributes
#ApplicationLabel: Websockets Example
#VersionCode: 1
#VersionName:
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: unspecified
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
#End Region
Sub Process_Globals
Private wsh As WebSocketHandler
Private link As String = "ws://IP ADDRESS OF PC:51042/ws"
End Sub
Sub Globals
Private btnConnect As Button
Private lblServerTime As Label
Private lblStatus As Label
Private btnSend As Button
Private EditText1 As EditText
End Sub
Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
wsh.Initialize(Me, "wsh")
End If
Activity.LoadLayout("1")
End Sub
Sub wsh_ServerTime(Params As List)
'example of a server push message
lblServerTime.Text = "Server Time: " & Params.Get(0)
End Sub
Sub btnSend_Click
Dim data As Map
data.Initialize
data.Put("message", EditText1.Text)
wsh.SendEventToServer("Device_Message", data)
EditText1.RequestFocus
EditText1.SelectAll
End Sub
Sub EditText1_EnterPressed
If btnSend.Enabled Then btnSend_Click
End Sub
Sub wsh_Connected
UpdateStatus
End Sub
Sub wsh_Closed (Reason As String)
UpdateStatus
ToastMessageShow(Reason, True)
End Sub
Sub Activity_Resume
UpdateStatus
End Sub
Sub UpdateStatus
If wsh.ws.Connected Then
lblStatus.Text = "Status: Connected"
Else
lblStatus.Text = "Status: Disconnected"
End If
btnConnect.Enabled = Not(wsh.ws.Connected)
btnSend.Enabled = wsh.ws.Connected
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub btnConnect_Click
wsh.Connect(link)
lblStatus.Text = "Status: Connecting..."
End Sub
[/CODE]