Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteEndpoint unavailable #2

Open
h-bahrami opened this issue Jun 16, 2020 · 0 comments
Open

RemoteEndpoint unavailable #2

h-bahrami opened this issue Jun 16, 2020 · 0 comments

Comments

@h-bahrami
Copy link

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 ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant