hi everyone , i am trying b4a with websocket server using libwebsocket on C++ , but show message : Server 404 not found on android application .
why it happens ? both are incompatible ?
why it happens ? both are incompatible ?
#Region Project Attributes
#ApplicationLabel: B4A 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://192.168.1.4:8090"
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
<!DOCTYPE html>
<meta charset="utf-8" />
<title>WebSocket Test</title>
<script language="javascript" type="text/javascript">
var wsUri = "ws://192.168.1.4:8090";
var output;
function init()
{
output = document.getElementById("output");
testWebSocket();
}
function testWebSocket()
{
websocket = new WebSocket(wsUri);
websocket.onopen = function(evt) { onOpen(evt) };
websocket.onclose = function(evt) { onClose(evt) };
websocket.onmessage = function(evt) { onMessage(evt) };
websocket.onerror = function(evt) { onError(evt) };
}
function onOpen(evt)
{
writeToScreen("CONNECTED");
doSend("WebSocket rocks");
}
function onClose(evt)
{
writeToScreen("DISCONNECTED");
}
function onMessage(evt)
{
writeToScreen('<span style="color: blue;">RESPONSE: ' + evt.data+'</span>');
websocket.close();
}
function onError(evt)
{
writeToScreen('<span style="color: red;">ERROR:</span> ' + evt.data);
}
function doSend(message)
{
writeToScreen("SENT: " + message);
websocket.send(message);
}
function writeToScreen(message)
{
var pre = document.createElement("p");
pre.style.wordWrap = "break-word";
pre.innerHTML = message;
output.appendChild(pre);
}
window.addEventListener("load", init, false);
</script>
<h2>WebSocket Test</h2>
<div id="output"></div>