Hi,
The example is working well for me on my local computer. Once I deployed at server where I have Public IP, Jar file could not run. Getting error while running Jar file.
Apart from Jar file anything need to implement at server.
Please help.
Below error I got while executing Jar file.
D:\New Folder>java -jar result.jar
2015-05-16 09:20:07.381:INFO::main: Logging initialized @400ms
2015-05-16 09:20:07.663:INFO

ejs.Server:main: jetty-9.1.z-SNAPSHOT
2015-05-16 09:20:07.725:WARN

ejh.MimeTypes:main: java.util.MissingResourceExcep
tion: Can't find bundle for base name org/eclipse/jetty/http/encoding, locale en
_GB
2015-05-16 09:20:07.803:INFO

ejsh.ContextHandler:main: Started o.e.j.s.ServletC
ontextHandler@51016012{/,file:/D:/New%20Folder/www,AVAILABLE}
2015-05-16 09:20:07.819:INFO

ejs.AbstractNCSARequestLog:main: Opened D:\New Fol
der\logs\b4j-2015_05_16.request.log
2015-05-16 09:20:08.210:INFO

ejs.ServerConnector:main: Started ServerConnector@
5ba23b66{HTTP/1.1}{0.0.0.0:51042}
2015-05-16 09:20:08.210:INFO

ejs.Server:main: Started @1285ms
Thanks
Sasidhar
This library allows you to create WebSocket connections with servers that support WebSockets.
It is based on this open source project:
http://autobahn.ws/android/#
The main benefit of this library is that you can use it to communicate with
B4J WebApp solutions.
The attached example includes a class named WebSocketHandler. With this class you can send events to the server and the server can send events to the device.
View attachment 24449
The server code is very simple:
Code:
Sub Class_Globals
Private ws As WebSocket
Private timer1 As Timer
End Sub
Public Sub Initialize
End Sub
Private Sub WebSocket_Connected (WebSocket1 As WebSocket)
ws = WebSocket1
timer1.Initialize("timer1", 1000)
timer1.Enabled = True
End Sub
Sub Timer1_Tick
'This method will raise the event on the device
ws.RunFunction("ServerTime", Array As Object(DateTime.Time(DateTime.Now)))
ws.Flush
End Sub
'event from the device
Sub Device_Message(Params As Map)
Log("Device message: " & Params.Get("message"))
End Sub
Private Sub WebSocket_Disconnected
timer1.Enabled = False
Log("disconnected")
End Sub
Sending events to the server
WebSocketHandler.SendEventToServer takes the event name (not prefix in this case) and the data. The data is a Map that is converted to a JSON string. Note that the event name must include an underscore.
Code:
Sub btnSend_Click
Dim data As Map
data.Initialize
data.Put("message", EditText1.Text)
wsh.SendEventToServer("Device_Message", data)
End Sub
Receiving events from the server
Code:
Sub wsh_ServerTime(Params As List)
'example of a server push message
lblServerTime.Text = "Server Time: " & Params.Get(0)
End Sub
The sub name in this case is made of the prefix set in the Initialize method and the event name as received from the server. There should be a single parameter which is a List.
How to run this example?
You need the latest version of B4J:
http://www.b4x.com/android/b4j.html
Download and run the server example.
You will need to open the firewall port (51042).
Set the address in the client code to match the server address.