tomcat - Simple Websocket Client in Java - Connection issue -


i'm trying write simple websocket client in java connect 3rd party websocket server (i have no access server).

i can connect , communicate websocket server using javascript in browser, when try , same thing using java client fails connect.

with same java client can connect tomcat websocket server have running, think it's sort of compatibility issue between client , server. (i'm using tomcat 7.0.56 libraries websocket client).

this error get...

error

javax.websocket.deploymentexception: http request initiate websocket connection failed     @ org.apache.tomcat.websocket.wswebsocketcontainer.connecttoserver(wswebsocketcontainer.java:344)     @ org.apache.tomcat.websocket.wswebsocketcontainer.connecttoserver(wswebsocketcontainer.java:166)     @ com.cvr.instant.ws.websocketclient.connect(websocketclient.java:44)     @ com.cvr.instant.ws.testws.start(testws.java:17)     @ com.cvr.instant.ws.testws.main(testws.java:37) caused by: java.io.eofexception     @ org.apache.tomcat.websocket.wswebsocketcontainer.processresponse(wswebsocketcontainer.java:595)     @ org.apache.tomcat.websocket.wswebsocketcontainer.connecttoserver(wswebsocketcontainer.java:317) ... 4 more 

websocketclient

import java.io.ioexception; import java.net.uri; import java.net.urisyntaxexception;  import javax.websocket.clientendpoint; import javax.websocket.closereason; import javax.websocket.containerprovider; import javax.websocket.deploymentexception; import javax.websocket.onclose; import javax.websocket.onmessage; import javax.websocket.onopen; import javax.websocket.session; import javax.websocket.websocketcontainer;  @clientendpoint public class websocketclient {      protected   websocketcontainer container;     protected   session usersession = null;      public websocketclient() {         container = containerprovider.getwebsocketcontainer();     }      public void connect(string sserver) {            try {               usersession = container.connecttoserver(this, new uri(sserver));              } catch (deploymentexception | urisyntaxexception | ioexception e) {                 e.printstacktrace();             }      }      public void sendmessage(string smsg) throws ioexception {         usersession.getbasicremote().sendtext(smsg);     }      @onopen     public void onopen(session session) {         system.out.println("connected");     }      @onclose     public void onclose(session session, closereason closereason) {     }      @onmessage     public void onmessage(session session, string msg) {         system.out.println(msg);     }      public void disconnect() throws ioexception {         usersession.close();     } } 

running client

import java.io.ioexception;  public class testws {      public websocketclient wsc;     public testws() {     }      public void start() throws interruptedexception, ioexception {          wsc = new websocketclient();         wsc.callback = this;         wsc.connect("ws://192.168.0.25:9000");         thread.sleep(1000);         wsc.disconnect();     }       public static void main(string[] args) throws interruptedexception, ioexception      {         testws t = new testws();         t.start();         thread.sleep(1000);     }  }     

i'm new websocket clients (and new websockets in general). can give appreciated!

i found issue - ws address required '/' on end of when being run java client.

javascript ws://192.168.0.25:9000

java ws://192.168.0.25:9000/

not sure why required in java - solved issue...


Comments

Popular posts from this blog

python - TypeError: start must be a integer -

c# - DevExpress RepositoryItemComboBox BackColor property ignored -

django - Creating multiple model instances in DRF3 -