How to run/deploy websocket in tomcat - java

I have created a websocket server using the tomcat libraries. I am using Eclipse and my websocket client is written in java using tyrus libraries.
But the way I am deploying the websocket server doesn't seem right.
Currently, I am doing Right Click>Run on Server.
It tries to open the socket in the browser using http and gets a 404.
But the web socket gets deployed anyways in this process, and clients can connect to it.
Is there a cleaner way, by which I can deploy a websocket on Tomcat server through Eclipse?

Related

Websockets not working properly on tomcat8 server

Below are the two scenarios that I am trying.
I have deployed application on server(tomcat8) using eclipse IDE. and then connecting the client with server using websocket protocol. It is working fine.
I have installed tomcat8 on a server machine, deployed the application and then connecting the client with server using websocket protocol. Then I am getting 404 not found error.
also If I run any jsp file on server using http protocol then it is working properly.
can anybody tell what I need to do to resolve this issue?

How do I use nanohttpd websockets from a client app?

I have implemented a websocket server using nanohttpd in java. I can access the websocket server from js in a web page. It works great.
However, now I'd like to create a java based client that will connect to the same server.
Does nanohttpd have a set of java classes to connect to the websocket server? In other words, the server is running in java but now I want a separate java client program to connect to it.
If so, what is the minimum java code to connect to the server?
If not, how would you suggest I connect to the websocket server in java?
There are plenty of third party Java Web Socket client implementations you can use. This is one of them.

Running a Java Application to run on a tomcat sever

I have created a Socket Server application that will accept Client connections from other computers on the local network. This is application is run from a public static void main method. and is a very standard java application.
I have also created a web service that runs on tomcat, it also uses java. The web service will http post accept request from any internet connected device.
Once the web service receives a request I would like it to send instructions through the socket server and send some data to the client connected.
I would like to run the socket server applicaiton within the web service so that the web service has access to the socket server without having to connect as a client.
What is the best way to run a standard java app so that the tomcat server will start the application when it starts up? should i run it as a servlet or is there a better way to have the web service access the socket
An application opening its own server socket within a proper application server is pointless and possibly counter productive IMO.
Think about it: Tomcat is probably running on port 8080. Your application is hypothetically going to be running on port 9080. What port do you think clients will need to connect to, to consume your service? And if you answered that correctly, what service/benefit are you then expecting Tomcat to provide you, if your clients are in fact, not going to interact with tomcat at all?
You don't need a (full) application server to run your own personal server. You have the option of:
a Java web service without a web application server, which lets you deploy a full JAX-WS webservice within the vanilla JSE, no application server required
Using the jdk's embedded HTTP server to process your requests
Deploying your standalone application as a windows (or other OS) service

Proxy for Tomcat outgoing HTTP requests

I have a JavaEE web application deployed in an Apache Tomcat 7.0.6 under Windows 7 which comunicates with a remote web service to request some data. I would like to intercept the comunication between them with an HTTP proxy, like BurpSuite (http://www.portswigger.net/burp/), so I can see the HTTP messages sent and received by the JavaEE application deployed in Tomcat. Already tried to set my BurpSuite (listening on port 8090/TCP) as a proxy system in Windows 7 and specifying some options for JVM when runs Tomcat (-Dhttp.proxyHost=10.0.2.16 -Dhttp.proxyPort=8091 -Dhttps.proxyHost=10.0.2.16 -Dhttps.proxyPort=8091).
I've been looking for a way to do this but I didn't find anything usefull. Could you please give me hand?
Greetings and thanks in advance.

Websocket on Tomcat 7.0.39 on openshift

I've just successfully installed Apache Tomcat 7.0.39 on my openshift account (tomcat-ngoanhtuanthesis.rhcloud.com/). I know that tomcat 7.0.39 has supported Websocket. In my local computer, I can run my web socket aplication properly, but I cannot run it in the openshift server. However, my web service application can run very well. I've searched over the Internet for the whole week but I couldn't find any solution. Can anyone help me? Thank you in advance!
Note: here is my Web service:
tomcat-ngoanhtuanthesis.rhcloud.com/TrueTrafficServerAlpha2/
And here are some websocket examples integrated in Tomcat 7.0.39. These examples cannot run even though they are very simple.
http://tomcat-ngoanhtuanthesis.rhcloud.com/examples/websocket/
Did you read this? https://www.openshift.com/blogs/paas-websockets
WebSockects are currently under staging on openshift, and are available on alternative ports.
How to access Preview WebSockets Support?
You will need to connect to
specific ports, as the main routing layer is still Apache based and
does not support WebSockets.
So, for plain WebSockets ws:// you will use port 8000 and for secured
connections wss:// port 8443. Here's an example:
http://app-lovingwebsockets.rhcloud.com/ <= your current HTTP URL
http://app-lovingwebsockets.rhcloud.com:8000/ <= WebSockets enables HTTP URL
https://app-lovingwebsockets.rhcloud.com/ <= your current HTTPs URL
https://app-lovingwebsockets.rhcloud.com:8443/ <= WebSockets enables HTTPs URL
So, just open your samples here, and they will just work (hopefully):
https://tomcat-ngoanhtuanthesis.rhcloud.com:8443/examples/websocket/

Categories