Skip to content

RemoteEndpoint unavailable #2

Description

@h-bahrami

Hi,
I have strange error happening while sending ByteBuffer to remote client.
The client is a noVNC client, with node-websockify and tightvnc worked perfectly

@OnWebSocketConnect
public void onConnect(final Session session) throws IOException, InterruptedException {
	System.out.println("Connect: " + session.getRemoteAddress().getAddress());
	System.out.println(session.getUpgradeRequest().getRequestURI());		

	System.out.println("session open ? " + session.isOpen());
	vncSocket = new Socket("127.0.0.1", vncPort);
	Thread readThread = new Thread(new Runnable() {
		public void run() {
			try {
				System.out.println("session open ? " + session.isOpen());
				byte[] b = new byte[1500];
				int readBytes;
				while (true) {
					readBytes = vncSocket.getInputStream().read(b);
					System.out.println("session open ? " + session.isOpen());
					System.out.println("read bytes " + readBytes + ", " + new String(b));
					if (readBytes == -1) {
						break;
					}
					if (readBytes > 0) {
						System.out.println("session open ? " + session.isOpen());
						ByteBuffer bb = ByteBuffer.wrap(b, 0, readBytes);
						session.getRemote().sendBytes(bb);
					}
				}
			} catch (IOException e) {
				e.printStackTrace();
				System.err.println(e);
			}
		}
	});
	readThread.start();

}

the error and console output is
session open ? true

Exception in thread "Thread-8" org.eclipse.jetty.websocket.api.WebSocketException: RemoteEndpoint unavailable, current state [CLOSED], expecting [OPEN or CONNECTED]
at org.eclipse.jetty.websocket.common.WebSocketSession.getRemote(WebSocketSession.java:308)
at com.hossein.main.WebSockify$1.run(WebSockify.java:91)
at java.lang.Thread.run(Unknown Source)

looks like the session.open() returns true but next line session.getRemote().sendBytes() causes the error.
can you help me figure out why ?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions