Description
I'm using a mongoose (https://github.com/valenok/mongoose.git) websocket server and trying to talk to it using async-http-client. Using a fairly simple client (take straight from the asynchttpclient github page). My client code is at the bottom of of this post. I'm using asynch-http-client-1.7.16.jar and netty-3.6.3.Final.jar
This is the other side of the same issue that I posted on the mongoose mailing list:
https://groups.google.com/forum/?fromgroups=#!topic/mongoose-users/GsCFx9tr7JA
But I will go ahead and repeat: I keep getting a "Websocket is null" error whenever I try to run the Client (I'm using Eclipse). Here's the bad case:
Error: WebSocket is null
CONNECTED
What is very strange is that when I put a breakpoint in websocket.c and then step through the code with gdb, I see everything behaving properly. Good case output:
CONNECTED
server says:server ready
server says:Hello world
server says:exit
Based on the suggestion from the websocket developer, I ran wireshark and captured the trace in both cases. After reviewing it, it appears the problem may be on the client side. Please see attached images of wireshark's output. In the good case, the client seems to send additional data before the "server_ready" comes back from the server. TIA for your help.
package com.example;
import com.ning.http.client.*;
import com.ning.http.client.websocket.*;
class AsyncClient {
public static void main(String[] args) {
AsyncHttpClient c = new AsyncHttpClient();
WebSocket websocket = null;
try {
websocket = c.prepareGet("ws://localhost:8080/foo")
.execute(new WebSocketUpgradeHandler.Builder().addWebSocketListener(
new WebSocketTextListener() {
public void onMessage(String message) {System.out.println("server says:" + message);}
public void onOpen(WebSocket websocket) {
System.out.println("CONNECTED");
websocket.sendTextMessage("Hello world"); //.sendMessage("...");
websocket.sendTextMessage("exit");
}
public void onClose(WebSocket websocket) {System.out.println("Connection closed");}
public void onError(Throwable t) {
System.out.println("Error: " + t.getMessage());
}
public void onFragment(String fragment, boolean last) {}
}).build()).get();
} catch (Exception e) {
e.printStackTrace();
} finally {
//websocket.close();
//c.close();
}
}
}