I've created a basic java EE 7 chat application - with Intellij Ultimate 14 - that lets users send messages and receive messages (using sessions, no room, no user identification).
I've tried the application by itself on a glassfish 4.1 server on windows 8.1 : it works perfectly.
Now I'm trying to run it in an ubuntu 14.04 server hosted in virtualbox (same glassfish and java ee version), this is so that I can later work on clustering the application.
When I install the application on the ubuntu server, using the web based interface (that I access from the windows host), I can load the application in a chrome, but the websocket doesn't seem to connect properly and therefore I cannot send any message at all.
By the way, I've tried connecting the websocket on the glassfish installed on the windows and it works fine.
Here is the html side of the app connecting the websocket to the server :
var host = "ws://" + document.location.host + "/GlassFish7_war/test";
wsocket = new WebSocket(host);
wsocket.onmessage = onMessage; // the function that displays received messages
and here is the relevant part of the server accepting the socket :
#ServerEndpoint("/test")
public class MyEndPoint {
#OnOpen
public void openConnection(Session session) {
session.getBasicRemote().sendText("hello there !");
// [...]
}
}
you guessed it : I never receive the "hello there !" message on the client side.
I think the problem might come from the configuration of the virtualbox network, yet I can't seem to figure out what to do about it. Currently I have a bridged and a NAT adapter.
Any help would be greatly appreciated !
Thanks a lot !
Related
I'm trying to develope an android application (with min-API-Level 28) with Java that communicates with an other device over a socket connection. One device is creating a Server instance and the other device should connect to this server.
For this purpose, I'm using Android-Emulator instances provided by Android Studio.
I followed the instructions at https://developer.android.com/studio/run/emulator-networking#connecting , but encountered that the provided IP-Adress ranges are not the same for every API-Level.
One Emulator-Instance running API 28 is using 192.168.232.0/24 address range, the other one running API-30 is using the provided 10.0.2.0/24 range.
So given the following scenario:
the Server (running on an API-28 Emulator-Instance) is creating the ServerSocket:
this.serverSocket = new ServerSocket();
// 192.168.232.2 is the device's IP-Address IF(!) the Emulator-Instance uses API Level 28
// 55555 the specific ServerPort
this.serverSocket.bind(new InetSocketAddress("192.168.232.2", 55555));
and after that accept incoming connections:
client = this.serverSocket.accept();
the Client (running on an API-30 Emulator-Instance) is trying to connect to this Server:
this.server = new Socket("10.0.2.2", 55556);
as described in the provided docs, 10.0.2.2 is the developement Device aka my Computer and 55556 a chosen local-port.
On the Server-Instance I added a redirect via the android emulator console
redir add tcp:55556:55555
But the Client can't connect to the Server. So far I'm clueless.
Any ideas what went wrong here?
#Edit - Tried to clarify that I'm using Android Emulators instead of real Devices
We have a Java web application at http://ourapp.com hosted at Heroku and the frontend of the app cannot connect to the WebSocket endpoint (endpoint) running in a Heroku dyno. We have tried these URIs:
ws://ourapp.com/endpoint
ws://ourapp.com:80/endpoint
ws://ourapp.com:8080/endpoint
ws://ourapp.com:8084/endpoint
ws://ourapp.com:443/endpoint
wss://ourapp.com/endpoint
wss://ourapp.com:80/endpoint
wss://ourapp.com:8080/endpoint
wss://ourapp.com:8084/endpoint
wss://ourapp.com:443/endpoint
None of the above open a connection. What are we missing here?
PS: I have set up a test ground: http://vakuutustiedot-dev.herokuapp.com/websocket.test.html (the URI is PROTOCOL:vakuutustiedot-dev.herokuapp.com:PORT/trial)
The target app runs in a Heroku Apache Tomcat 8.5.38.
What comes to the port number, I am not sure how to get one.
Perhaps you have missed adding the support of WebSockets to Heroku, like in this answer (https://stackoverflow.com/a/50002416/11197115)?
Maybe you should try configuring the proxy attribute of devServer. This attribute is used when the frontend app and backend api are not running on the same host. Perhaps the below setting might solve your problem.
module.exports = {
devServer: {
proxy: 'ws://ourapp.com:8080/endpoint'
}
}
For more info see the docs: https://cli.vuejs.org/config/#devserver
I am trying to build a chat application.
+Server : I use java websocket to create an endpoint. Here is my endpoint:
#ServerEndpoint("/server")
public class ChatServer {
//My code is ok ! Tested in localhost
}
+Client : I use java swing to create GUI. In my localhost, I use this URL :
ws://localhost:8080/ChatServer-1.0/server
to connect to Server Endpoint and my app run successful.
-> I have deployed my server endpoint to Heroku
My Heroku Server Endpoint
How can my client to connect to server endpoint ?
I have tried to use:
wss://jp-chatting-server.herokuapp.com/server
But it gives a 404 code.
I think you have used instruction for webapp-runner. I'm afraid this solution will not work for websockets. It is because support of websocket is not implemented yeat. Issue with websocket in webapp-runner. I see one of the options in using Tomcat 7 and it's custom implementation. Like in this example.
I have a locally working JAVA RMI Applicaton(Server & Client).
I have used Eclipse & a plugin(Genady) to write & run these applications.
There are three parts in my project:
1. Server
2. Interface(Common for both client & server)
3. Client
Local deployment, using Eclipse(+plugin), works perfectly. The client uses the common interface(added to the "Build Path") to communicate(to n fro) with the server(which also has the common interface added to its Build Path in eclipse).
And now, I'm planning to test the same system in two different computers, both having Internet connection.
What do I do now?
Should I be installing Apache on one computer(Server) & put the Server+Interface files(class-files) into the web-accessible directory? & then run the Client-files(having both client & interface class files) from another computer(Client)??
Can someone help me configure this? I mean, a step-by-step guide as to what I should be doing in order for the remote deployment to work?
Is using Apache(or any web server application) compulsory?? Any other alternative for my application to work without using a web server(I mean, like direct connection or something?)?
(I feel I've given all the info that is required. But if any more info is needed, please ask.)
This is my final year project & my final demo is coming up soon!
Thank you, in advance!
I don't know what Genady does since I rarely use Eclipse.
Developing RMI applications is very easy anyway.
Pack the server code and run it on the remote machine (the R in RMI)(a.k.a. server host), it should register itself with the Registry which by default uses port 1099 but you can create a registry in any port you like:
MyRemoteInterface stub = (MyRemoteInterface) UnicastRemoteObject.exportObject(server, 0); //I don't know if this is needed anymore, or you could make the "server" extend UnicastRemoteObject
int thePortUsedInTheServer = 1099; //default
Registry registry = Registry.createRegistry(thePortUsedInTheServer);
registry.rebind("Server", stub));
Pack the client code and run it on the client(s) (the M+I in RMI), it should locate the Registry in the remote machine (host+port):
String host = ...; //the host where the server is
int port = ...; //the port used in the server
Registry registry = LocateRegistry.getRegistry(host, port);
MyRemoteInterface stub = (MyRemoteInterface)registry.lookup("Server");
stub.myRemoteMethod(); //call your remote methods
The javadoc should help you out. Nothing else is required, no Apache, etc. Watch out for aggresive anti-virus software, firewalls, and the like. Those are the only real issues after you get the gist of it.
I am trying to make tic tac toe using websockets running on glassfish. I've download this example form git. Firstly, I want to test it, so I run it as a normal java process on my machine. I also made a tiny change to the tictacto.js
if (typeof MozWebSocket != "undefined") { // (window.MozWebSocket)
appType = "Mozilla";
} else if (window.WebSocket) {
appType = "Chrome";
} else {
alert('ERROR: This browser does not support WebSockets');
}
and then
if (appType == "Mozilla") {
ws = new MozWebSocket(WEBSOCKET_URL);
//alert('MozWebSocket');
} else {
ws = new WebSocket(WEBSOCKET_URL);
//alert('WebSocket');
}
When I open the test page with FF 10.0 the event onclose is only invoked and I get the status "The WebSocket Connection Has Been Closed." then I open the test page with Chrome 17.0.963.46 m. The status is also "The WebSocket...." but server throws an exception.
run:
TicTacToe Server: Listening on port 9000
java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:43)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:218)
at sun.nio.ch.IOUtil.read(IOUtil.java:186)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:359)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:323)
at org.jboss.netty.channel.socket.nio.NioWorker.processSelectedKeys(NioWorker.java:282)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:202)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:722)
What is the cause? I though about a few possilbe issues:
I use Netty 3.2.6.Final from JBoss repository. It could use different standard of websockets than the browsers.
running it as a java process on my machine istead as a webserver. But Netty doesn't have any dependencies that would require it.
Wrong locations. var WEBSOCKET_URL = "ws://localhost:9000/websocket"; and html location is C:...web\kolo\src\main\webapp\t.html
I am using Netbeans 7.1 and glassfish 3.1
Fixed project can be found https://github.com/lukasz-madon/Tic-Tac-Toe-with-WebSocket
I could be the web socket version. Here's a table of web socket versions and which browser supports which.
From memory, 3.2.6 only supported HyBi-00.
Try Netty 3.3. It supports a number of versions.