Closed
Description
If I change Draft_17() to Draft_75 or Draft_76. The following client just hangs after connecting.
public class JwsClient extends WebSocketClient {
int x;
public JwsClient( String location ) throws Exception {
super(new URI( location ), new Draft_17() );
}
public void onMessage( String message ) {
System.out.println( "Client got: " + ++x + " " + message.substring(0,50));
// try{Thread.sleep(1);}catch(Exception e){e.printStackTrace();}
send(message);
}
public void onOpen( ServerHandshake handshake ) {
System.out.println( "connected to server" );
char[] chars = new char[100000];
Arrays.fill(chars, 'x');
String message = new String(chars);
send(message);
}
public void onClose( int code, String reason, boolean remote ) {
System.out.println("disconnected from server. " + code + " " +reason);
}
@Override
public void onError( Exception ex ) {
ex.printStackTrace();
}
public static void main( String[] args ) throws Exception {
WebSocket.DEBUG = false;
String location = "wss://localhost:8887";
JwsClient jwsClient= new JwsClient( location );
jwsClient.connect();
}
}
The server code is as follows:
public class JwsServer extends WebSocketServer {
int rcvdMsgCtr;
public JwsServer( int port ) throws UnknownHostException {
super( new InetSocketAddress( port ) );
}
@Override
public void onOpen( WebSocket conn, ClientHandshake handshake ) {
System.out.println( conn.getRemoteSocketAddress().getAddress().getHostAddress() + " just connected." );
}
@Override
public void onClose( WebSocket conn, int code, String reason, boolean remote ) {
System.out.println( conn.getRemoteSocketAddress().getAddress().getHostAddress() + " just disconnected." );
}
@Override
public void onMessage( WebSocket conn, String message ) {
String dispMsg = null;
if(message.length()<50){
dispMsg = message;
}
else
{
dispMsg = message.substring(0,50);
}
System.out.println( "Server got message " + + ++rcvdMsgCtr + " " + dispMsg );
conn.send(message);
}
@Override
public void onError( WebSocket conn, Exception ex ) {
ex.printStackTrace();
if( conn != null ) {
// some errors like port binding failed may not be assignable to a specific websocket
}
}
public static void main( String[] args ) throws Exception {
WebSocket.DEBUG = false;
int port = 8887; // 843 flash policy port
try {
port = Integer.parseInt( args[ 0 ] );
} catch ( Exception ex ) {
}
JwsServer s = new JwsServer( port );
s.start();
System.out.println( "JwsServer started on port: " + s.getPort() );
}
}