Issues with Flutter and Phoenix Channels - flutter

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.

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());

Flutter - Socket.Connect() - SocketException: OS Error: Connection timed out

When I was working on debug mode (with "flutter run") by using my device (real), Socket.Connect() method doesn't work.
Also I would like to say that this Connect method is in "dart:io" library.
In shortly;
I opened a server (TCP) with Python.
I wrote the Flutter client like below to be able to connecting to the server in Python.
Future den() async {
print("Started");
Socket sock = await Socket.connect("192.168.0.159", 5431);
print("Done +++++++++++++++++++++++++"); }
However, I took a SocketError as Connection time out.
The error message I took:
E/flutter (17655): [ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: SocketException: OS Error: Connection timed out, errno = 110, address = 192.168.0.159, port = 43836
NOTE:
I tried to change the manifest file by adding INTERNET permission, but it is not working.
It was a strange problem, because there is no problem the code I shared. Windows Defender performed a rule to block to open a port as server. Hence, I started the server on my machine, however, I couldn't connect it from my Android device.
Maybe, the error code that is shown by Flutter isn't clear. If you took a error about socket programming for connection or binding, looking to Defender (or firewall) can be affective method. Unfortunately, as I was just starting to learn Flutter, I thought of checking out Defender afterwards.

Flutter socket io not connecting

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

Smack API throws "Session establishment not offered by server" Exception

I'm trying to connect to the Vines XMPP server from Java using the Smack API. However, when I use the following connection code:
ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration("localhost", 5222);
this.connection = new XMPPConnection(connectionConfiguration);
connection.connect();
connection.login(AUCTION_LOGIN, AUCTION_PASSWORD, AUCTION_RESOURCE);
I receive the following error message:
Caused by: Session establishment not offered by server:
at org.jivesoftware.smack.SASLAuthentication.bindResourceAndEstablishSession(SASLAuthentication.java:456)
I understand the issue to be related to sessions now being deprecated from the XMPP protocol. I've been unsuccessful in finding a way to use the ConnectionConfiguration class and others to work around this problem.
You appear to be using an old, vulnerable Smack version (i.e. < 4.0.0).
The current stable Smack version does not throw such an exception, as it considers session binding to be option. It can even be completly disabled with setLegacySessionDisabled(true).

How to receive messages in a GWT App using Kaazing Websockets <type>proxy</type> configuration?

I'm trying to build a GWT (2.4.0) application that can communicate (full-duplex) with a server using a text-based protocol. To accomplish this I'm using Kaazing Websocket Gateway Version 3.3.2 to act as a proxy.
GWT App <-----[websocket]-----> Kaazing <-----[tcp]-----> Backend Server
This is my Kaazing configuration:
<service>
<accept>ws://127.0.0.1:9444/foobar</accept>
<connect>tcp://localhost:50189</connect>
<type>proxy</type>
<cross-site-constraint>
<allow-origin>http://127.0.0.1:8888</allow-origin>
</cross-site-constraint>
</service>
This setup works with the Java implementation of the Kaazing client. Now I want to use this service in a GWT application.
This is my Code for the GWT client implementation:
WebSocket ws;
try {
ws = new WebSocket("ws://127.0.0.1:9444/foobar");
ws.addCloseHandler(new CloseHandler() {
#Override
public void onClose(CloseEvent ev) {
}
});
ws.addMessageHandler(new MessageHandler() {
#Override
public void onMessage(MessageEvent ev) {
System.out.println(ev.getData());
}
});
ws.addOpenHandler(new OpenHandler() {
#Override
public void onOpen(OpenEvent ev) {
}
});
} catch (WebSocketException e) {
e.printStackTrace();
}
The GWT client can successfully send text to the backend server. It just can't process any response from the server. A JavaScript Exception is thrown as soon as ev.getData() is called.
Uncaught JavaScript exception [Uncaught java.lang.ClassCastException: com.google.gwt.core.client.JavaScriptObject$ cannot be cast to java.lang.String]
If I change the WebSocket address in the code above to ws://127.0.0.1:9444/echo to use the Kaazing echo service, any text I send is successfully received by the GWT application. If I change the service back to proxy (or broadcast) the above JavaScript exception is thrown every time a message from the server is received.
The same code in a Java program (using the Kaazing java client) works just fine.
As I am no GWT expert, is there any way I can further debug the problem or is there a simple solution I just fail to see?
I believe I've seen that issue before, do you mind sharing your gwtclient.gwt.xml file content? Or, maybe, try adding '' or '' depending on whether you are using ByteSocket or WebSocket in the 'gwtclient.gwt.xml' of the GWT client.
Hope this helps,
-Marcelo