Hi, I am new to tizen as I just got a samsung gear S2.
I'm trying to build an app that sends a websocket to a local IP adress but I can't seem to create the socket correctly.
I've tried this code :
var websocket;
var wsUri = "ws://websocket.org/echo.html/";
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)
{
console.log("CONNECTED");
doSend("test");
}
function onClose(evt)
{
console.log("DISCONNECTED");
}
function onMessage(evt)
{
console.log(evt.data);
websocket.close();
}
function onError(evt)
{
console.log(evt.data);
}
function doSend(message)
{
if(websocket.readyState === 1){
console.log("SENT: " + message);
websocket.send(message);
}else{
console.log("Too bad");
}
}
testWebSocket();
as a test but I get the following message : WebSocket connection to 'ws://websocket.org/echo.html/' failed: Unexpected response code: 301
I then tried with google's url : WebSocket connection to 'ws://google.com/' failed: Unexpected response code: 400 (also tried with wss://)
I also tried to do it with the local ip adr and got : WebSocket connection to 'ws://192.168.1.58:5260/' failed: Unexpected response code: 200
and all other attempt afterwards gave me WebSocket network error: Could not connect to 192.168.1.58: Connection refused
(At this stage I'm pretty sure my server crashed which is why I can't connect anymore).
I made this app on Android studio for another device but I understand sockets and WebSockets are quite different. Can someone tell me what I'm doing wrong ?