I wanted to use socket.io in my RN project. Everything was ok, until I disabled chrome debugger. Now socket.io just doesn't work, nothing happens.
This is not the same problem: Is it possible to combine React Native with socket.io
What's your React Native version?
In your url add ws:// like :
var soc = socket('ws://192.168.1.101',{
jsonp: false
})
It works fine on device with RN v0.21.0.
After I upgrade RN to 0.24.0, it doesn't work again.
I have also got this problem. I fixed this from this link
You have to initialize socket like this
this.socket = io('http://192.168.0.101', {jsonp: false, transports: ['websocket']});
Related
We have a bot running in Azure (Web App Bot) that I'm trying to embed on a website. The bot is based of the Bot Builder V4 SDK Tamplate CoreBot v4.9.2. At first I used the iframe to embed the bod. This worked but didn't provide the features we need, so now im changing it to use DirectLine.
My code on the webpage looks like this:
<script crossorigin="anonymous"
src="https://cdn.botframework.com/botframework-webchat/latest/webchat.js"></script>
<div id="webchat" role="main"></div>
<script>
(async function () {
const res = await fetch('https://[my bot name here].azurewebsites.net/.bot/v3/directline/tokens/generate',
{
method: 'POST',
headers: new Headers({
'Authorization': "Bearer [my token here]"
})
});
const { token } = await res.json();
window.WebChat.renderWebChat(
{
directLine: await window.WebChat.createDirectLineAppServiceExtension({
domain: 'https://[my bot name here].azurewebsites.net/.bot/v3/directline',
token
})
},
document.getElementById('webchat')
);
document.querySelector('#webchat > *').focus();
})().catch(err => console.error(err));
</script>
After some struggles I managed to fetch a token from https://[my bot name here].azurewebsites.net/.bot/v3/directline.
And I can see the chat window on my webpage, but is says connecting for a while then it changes to Taking longer than usual to connect, like this:
In the Chrome console there is an error saying Failed to connect Error: Connection response code 500. When I check Chrome's Network tab I can see that the token generated completed with status 200 and that the websocket connection is open, like this:
----------EDIT---------
I just noticed that when go to https://[my bot name here].azurewebsites.net/.bot using a webbrowser, the resulting json is
{"v":"1.0.0.0.55fa54091a[some key?]","k":true,"ib":false,"ob":false,"initialized":true}
ib and ob should be true but are false, maybe this is part of the problem.
----------EDIT 2---------
OK so now I'm starting to go crazy.
Ashish helped me and at some point the ib and ob were true. They were true for most of yesterday. At some point yesterday they turned false for a short while (no more than 2 hours). I checked if someone had triggered the release pipeline but no recent releases. After that ib and ob magically turned true again and connecting to the direct line worked again.
Now this morning ib and ob were false again. And again no recent releases. I don't know what is causing this.
Does anybody know what's going on here or how to fix this? How do I find what causes ib and ob to be false?
Any help is appreciated! Thanks in advance. If you need more information, just ask and I'll post it.
If the ib and ob values displayed by the *.bot endpoint are false this means the bot and the Direct Line app service extension are unable to connect to each other.
Make sure you verify below things:
Double check the code for using named pipes has been added to the
bot.
Confirm the bot is able to start up and run at all. Useful
tools are Test in WebChat, connecting an additional channel, remote
debugging, or logging.
Restart the entire Azure App Service the bot
is hosted within, to ensure a clean start up of all processes.
Please check troubleshooting guide, it seems updated today. (still old date reflected some how, not sure why)
I'm trying to connect to a server using websockets. I've set up the port on the server, and am trying to connect through the Dev console in Chrome (also tried Firefox and got the same result).
I connect from the console using:
var websocket = new WebSocket('ws://localhost:5001');
This gives me the message "undefined". However, if I do
websocket.readyState
I get "1".
I then do
websocket.binaryType = 'arraybuffer';
which prints "arraybuffer".
If I then do something like
websocket.send("1+1");
it says undefined.
However, if I do all of this in an HTML file with JavaScript, it connects fine and I get the result "2", so it looks as though the Websocket itself is ok, and what I'm typing in is ok, but it's something to do with it being in the Dev Console that's the issue.
I don't know anything much about setting up Websockets.
I solved this by adding an onmessage function to the websocket:
websocket.onmessage = function (result) {
console.log(result.data);
}
I'm running in a very frustrating error, trying to connect an android (nativescript) app with socket.io
I've developed my app for ios and trying to port it to Android but socket.io won't connect, I narrowed the problem down to a simple hello world from the templates with only the socket.io plugin. It works with IOS but not with Android. I get silent errors
running this bit of code :
export class AppComponent
{
socket;
constructor()
{
console.log('constructor!');
this.socket = SocketIO.connect('https://eaglecar.org');
this.socket.on('connect', ()=>
{
console.log('Connect!');
});
this.socket.on('error', (error) =>
{
console.log('Error!');
console.log(error);
});
}
}
For information, this connects to a server with a let's encrypt ssl certificate.
IOS console output
CONSOLE LOG file:///app/app.component.js:8:20: constructor!
CONSOLE LOG file:///app/tns_modules/#angular/core/./bundles/core.umd.js:3053:20: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
CONSOLE LOG file:///app/tns_modules/nativescript-socket.io/common.js:41:22: nativescript-socket.io on connect []
CONSOLE LOG file:///app/app.component.js:11:24: Connect!
But with Android
it silently fails given neither Connect! nor Error!
JS: constructor!
JS: Angular is running in the development mode. Call enableProdMode() to enable the production mode.
At first I was thinking about a timing error, so I tried to attach the connect to a UI callback, the function gets called but with no errors.
Can't find anything interresting with adb logcat but this, seems normal :
08-04 15:10:24.377 11162 11162 V JS : constructor!
08-04 15:10:24.386 11162 11193 D NetworkSecurityConfig: No Network Security Config specified, using platform default
08-04 15:10:24.389 11162 11195 I System.out: (HTTPLog)-Static: isSBSettingEnabled false
08-04 15:10:24.389 11162 11195 I System.out: (HTTPLog)-Static: isSBSettingEnabled false
Just tried to change the connecting domain to something that does not exist and still no error in the console...
Additional tests :
2 tests I made :
I successfully loaded an image over https in the same app on the same
server with the same certificate
I successfully connected to a non secure socket.io server on
another port (3000) on Android.
Server side
var fs = require('fs');
var options = {
key: fs.readFileSync('../ssl/keys/[this_is_a_valid_key].key'),
cert: fs.readFileSync('../ssl/certs/[this_is_a_valid_cert].crt')
};
var server = require('https').createServer(options);
server.listen(443,'eaglecar.org');
var io = require('socket.io').listen(server);
io.on('connection', function(socket){
console.log('connected!!');
});
I had doubts and it appears to be true, Just replaced the certificate with a paid certificate from some well known vendor and now everything runs smoothly.. Apparently IOS recognises let's encrypt but android doesn't. At least the socket io plugin doesn't. because images are loaded just fine over https with let's encrypt.
I am building a Titanium based mobile application (iOS) in Appcelerator and want to connect it to Node.js(Socket.io) based server. For that I need a client side socket.io file which.
I tried to import the client side JS using 'require',
var io = require('socket.io'); //JavaScript Downloaded from here: https://github.com/socketio/socket.io-client/blob/master/socket.io.js
var socket = io.connect('http://localhost:3000');
I am getting the following error:
Script Error: Module "socket.io" failed to leave a valid exports object
Please let me know where I am going wrong or what is the way to use socket.io in Appcelerator.
Thanks In Advance.
I need to develop an application using WebSockets and Haxe.
I came upon this lib: http://lib.haxe.org/p/hxWebSockets
But it's outdated.
Then I found this blog post: http://bp.io/post/322
But the links to the code are broken :(
So, anyone out there knows any other WebSocket resource for Haxe?
If not, does someone has a clue where to start looking to start implementing my own solution?
Thanks!
If you use node.js as a platform, I'd recommend you to make bindings to socket.io. If you use another platform, I'd recommend to use socket.io as a reference implementation, or just port it to haxe, which shouldn't be that hard.
The lib you mentioned is indeed outdated. Luckily, someone made a new one, supporting the latest websocket protocol:
http://lib.haxe.org/p/WebSocket
...however, it's still a bit lower level than nodejs/socket.io
I am using haxe for a websockets application and using the js libraries:
import js.html.WebSocket;
Using the following function to connect to the server.
private function connect() {
trace("Calling connect");
try {
websocket = new WebSocket(connectionString());
websocket.onclose = onClose;
websocket.onerror = onServerConnectionError;
var openStream = initializeElementStream(cast websocket, "open");
openStream.then(onOpen);
var eventStream = initializeElementStream(cast websocket, "message");
eventStream.then(onMessage);
var closeStream = initializeElementStream(cast websocket, "close");
closeStream.then(onClose);
var errorStream = initializeElementStream(cast websocket, "error");
errorStream.then(onServerConnectionError);
}catch(err : Dynamic) {
trace("Error establishing connection " + err);
}
trace("Connection successful");
}
Will this work for you. I am sticking to standard js libraries for my project. This has worked for me since the project has no external dependencies.
I recently started using Haxe-Js-Kit and it has decent bindings for a lot of nodejs libs including Socket.IO.
https://github.com/clemos/haxe-js-kit/
Make sure you use the dev branch for development as it is quite more advanced than the haxelib or master branch.