Flutter socket io not connecting - flutter

I have a server using socket.io, and I'm trying to connect to it using https://pub.dev/packages/socket_io_client. I have ngrok running for the backend. When I run the following code, ngrok shows theres a connection, but the on connection event in the backend doesn't run, and in flutter it says it's disconnected:
IO.Socket socket = IO.io('http://my_ngrok_number.ngrok.io', IO.OptionBuilder().setTransports(['websocket']).build());
print(socket.connected);
socket.onConnect((_) {
print('connect');
socket.emit('msg', 'test');
});
socket.onConnecting((data) => print(data));
socket.onError((data) => print(data));
// When an event recieved from server, data is added to the stream
socket.on('event', (data) => streamSocket.addResponse);
socket.onDisconnect((_) => print('disconnect'));```
Flutter does output 'disconnect' every couple of seconds

I had same issue some days ago and the solution is downgrade your socket.io server to version 2.3.0 it will work

Related

Can't connect from flutter app to remote meteor server

I need to get data for flutter apps from a remote meteor server. Connecting locally to the local host and receiving data packets, and connecting to a remote server gives an error. I am consuming dart_meteor.
I/flutter (23037): MeteorClient[426707093] - Make a connection to wss://example.com/websocket
I/flutter (23037): WebSocketException: Connection to 'https://example.com:0/websocket#' was not upgraded to websocket
Code snippet for connection.
MeteorClient meteor = MeteorClient.connect(url: 'https://example.com');
void main() => runApp(MyApp());

ipfs pubsub not working across two remote peers

If I run this code on my pc, I see my message, but another person on a different pc running the same code doesn't see mine. Is this a NAT thing perhaps? Or am I using this wrong?
const Room = require("ipfs-pubsub-room");
const ipfs = require("ipfs");
ipfs.create({}).then(async (node) => {
const room = new Room(node, "room-name");
room.on("peer joined", (peer) => {
console.log("Peer joined the room", peer);
});
room.on("peer left", (peer) => {
console.log("Peer left...", peer);
});
// now started to listen to room
room.on("subscribed", () => {
console.log("Now connected!");
});
room.on("message", ({ from, data }) =>
console.log(from, JSON.parse(data.toString()))
);
room.broadcast(JSON.stringify({ bla: "hello" }));
});
Are you using this in Node.js or browser?
The problem should be that your peers are not connected between each other (or with a common set of peers running pubsub) to have the pubsub messages reliably forwarded. The first step for you to diagnose this is to use node.swarm.peers() and see if you have the other peer.
Considering your peer is not connected to the other person node, you need to manually connect it, or configure a discovery mechanism to help you (this is automatic discovery and connectivity is a known problem for the community and we will be working on improving this experience).
The simplest option is to use webrtc-star transport+discovery. You can see examples with it in ipfs browser exchange files and with libp2p.
With this, you will likely see the other peers connected and then be able to exchange Pubsub messages. You can see more about the discovery mechanisms available in Libp2p config.md and libp2p discovery examples.
Let me know if you could get your issue fixed

Issues with Flutter and Phoenix Channels

We're having some issues with our Flutter App and Pheonix Web Sockets. We know that the Backend is working properly, since the JavaScript client is fully functional. But with the Flutter app we can't connect to the server.
final socket = PhoenixSocket("ws://###.##/socket");
connectSocket() async {
await widget.socket.connect();
_channel = widget.socket.channel("test:lobby")
_channel.on("say", _say);
_channel.join();
}
One of the errors were gettig:
I/flutter ( 4227): WebSocket connection to ws://###.##:8080/socket?vsn=2.0.0 failed!: WebSocketException: Connection to 'http://###.##:8080/socket?vsn=2.0.0#' was not upgraded to websocket
On the client side we're using Phoenix Wings, the port and URL are correct.
Why does this keep happening?
Are there any other libraries for Flutter with Phoenix Interactions?
Is there a better documentation for phoenix_wings or for any other packages?
I had it working as
final socket = PhoenixSocket("ws://####.###/socket/websocket");
hth.

react-native websocket ERR_NAME_NOT_RESOLVED stopping network requests

Every now and then our react-native app has a problem connecting to our websocket (we're using sockjs). When this happens it blocks all network requests and essentially stops our app from functioning.
When it occurs the console doesn't stop logging:
GET http://192.168.0.11.xip.io:8080/sock/194/noeli4ep/eventsource
net::ERR_NAME_NOT_RESOLVED
This is our connect script, which runs when the app starts, it also runs when socket closes (this is so we can re-connect to the socket).
connectToServer() {
if (!this.flagConnect) {
this.webSocket = new SockJS(`${config.endpoint}sock`);
this.webSocket.onopen = this.onOpen; // Just sets this.opened to true
this.webSocket.onmessage = this.onMesssage; // Just reads the msgs
this.webSocket.onclose = this.onClose; // Re-calls connectToServer()
this.webSocket.onerror = this.onError; // Console.logs the error
}
}
We're using React-native 0.41 & using sockJS on the app & backend (nodejs).
I found that removing xip.io fixed this issue.
So using http://<ip>:><port> was fine.

Logstash TCP Input Crashing

We have a logstash (v2.3) setup with 1 queue server running RabbitMQ, 10 elasticsearch nodes and a web node for kibana. Everything "works" and we have a large number of servers sending logs at the queue server. Most of the logs make it in, but we've noticed many that just never show up.
Looking in the logstash.log file we'll see the following start showing:
{:timestamp=>"2016-07-15T16:21:34.638000+0000", :message=>"A plugin had an unrecoverable error. Will restart this plugin.\n Plugin: <LogStash::Inputs::Tcp type=>\"syslog\", port=>5544, codec=><LogStash::Codecs::JSONLines charset=>\"UTF-8\", delimiter=>\"\\n\">, add_field=>{\"deleteme\"=>\"\"}, host=>\"0.0.0.0\", data_timeout=>-1, mode=>\"server\", ssl_enable=>false, ssl_verify=>true, ssl_key_passphrase=><password>>\n Error: closed stream", :level=>:error}
This repeats about every second or so. We initially thought maybe max connections limit was being met but a netstat only shows about ~4000 connections, and our limit should be upwards of 65,000.
Why is this TCP plugin crashing so much?
Everything I've read online hints towards this being an older issue that was resolved with newer versions of Logstash, which we've long since installed. Whats confusing is that it is partially working, we're getting a ton of logs but also seem to be missing quite a bit.
Relevant conf file on Queue server:
queue.mydomain.com:
input {
tcp {
type => "syslog"
port => "5544"
}
udp {
type => "syslog"
port => "5543"
}
}
output {
rabbitmq {
key => "thekey"
exchange => "theexchange"
exchange_type => "direct"
user => "username"
password => "password"
host => "127.0.0.1"
port => 5672
durable => true
persistent => true
}
}
We recently added UDP to the above conf to test with it, but logs aren't making it in reliably to it either.
Just in case the Elasticsearch cluster conf is relevant:
We have a 10 node Elasticsearch cluster, setup to pull from the queue server, this works as intended and is on same version of Logstash as Queue server. They pull from the rabbitMQ server with the conf:
input {
rabbitmq {
durable => "true"
host => "***.**.**.**"
key => "thekey"
exchange => "theexchange"
queue => "thequeue"
user => "username"
password => "password"
}
}
Anyone have any ideas for us to try to figure out whats up with tcp-input plugin?
Thanks.