chat application deploy - java

I have created one sample chat application. In that chat application, I used JApplet and front end.
Till now I was testing my application in my desktop. It is working fine. Now I want to deploy my application over any webserver.
Now I have a few questions. Currently I am using Server socket as 8989 in my chatserver. When I was testing the application in my desktop, I used to start the server as stand alone.
What are the steps I have to follow when I deploy the application over tomcat or any other web server? Which port the client will listen?
How do I start my chat server? I am new to the socket concepts.

when you say you are hosting on the webserver, i believe that its an servlet/jsp based application , which will listen to your requests , in that case the listener will be invoked at the webserver default port either 80 / 8080 (being default). In case you want to change or check , you can go to the TOMCAT_INSTALLATION_DIR/conf/server.xml and check for tag containing the port number for weblistener, and change it to whatever value you feel like.
if thats not the case and you have your own thread which opens a socket for you , you really dont need a webserver, all you need is a host machine which will start the socket listener ( your custom) and then it will listen at the port that you have configured it to be at.

As far as I got it, you're having standalone application as a server, where you handle connections to particular port.
I think there is some confusion that should be clarified.
The very basic question is:
Why do you need your chat server to be running on the web server?
This should be clear to you prio to any later steps.
As web server is there basically to handle HTTP/S requests and that's not your case, as far as I got it. As you're probably running socket TCP/UDP communication.
For the web server however your client applet implemnentation could benefit of. If it would be referrend on a simple html page (deployed inside war) it could be simply redistributable to clients via url call in a web browser.
Maybe I'd preffer to use HTTP + JSON commununication, where you could benefit from web server usage (also on the server side) and would not need any other ports than standard ones.
Not sure if it still makes sence to answer your questions as it might be irrelevant for you, but let's see.
Answers to your questions:
Basically you need war archive (rather than jar one), as that's the one accepted by web servers. once you create it (you need to follow the correct folder/file structure inside) your app could be deployed to web server.
Which port the client will listen? Basically server is the listener here => no client port listening here.
This depends on your communication implementation decision. If still sticking with TCP/UDP one, I don't think web server would be beneficial here.

Related

Best way to expose http listening port in java based desktop application

I have a desktop application that is written in Java and that I have source code for.
I want to launch a process in this application based upon when I click a button in my web application.
I'm thinking that the browser can fire off a HTTP call to the desktop application on the loopback address. The application will only listen on the loopback address thereby preventing other machines from talking to the application.
If I take this route, I have to host some kind of http listener in my java desktop application. What is the best way to do this?
I have considered embedded tomcat and jetty, but I'm wondering if those aren't overkill or less secure due to a larger feature set, and I could run a http socket listener with something simpler.

Clarity about Client Server web application over HTTPS

I know the scope of this question is very large and its not appropriate to ask it here. But I don't know where to go.
I have a web application (client) + a web application (server). Both are working on tomcat on two different ports.
Now, I want the client to send and receive data to/from server using HTTPS/SSL, or in better terms, using a secured connection.
Need some guidance/clarity for this. Some questions that I have are:
Should I change some settings in TOMCAT so that my server runs on HTTPS ?
Should I make changes to client as well ?
How do I establish the connection via HTTPS ?
How do I know that data is transferred over HTTPS ?
u should state the content of the jsp page to be "contentType/https"

Tomcat Push to Java Client

I'm trying to build a Java web app that will let me browse a remote file system behind my NAT router. The client can talk outbound HTTP only.
I've got my Java client on the remote machine talking to my Tomcat server, which is then serving the data back up as web pages. Something like this:
File Server (java client) -> Web Server <- Browser
What I can't figure out is how to have the Tomcat server talk back to the remote Java client.
What I want to happen is:
User clicks on a folder in their browser.
Browser ajaxes to the server.
The Tomcat server contacts the remote java client.
The remote java client responds with the directory listing.
The Tomcat server sends back the new data formatted as HTML to the user.
I've looked at Comet and Tomcat 7's asynchronous stuff but I'm struggling!
If you need full-duplex communication over HTTP, than I strongly recommend using Atmosphere and Web Sockets. It simplifies server push a lot, and it's container agnostic (the framework).
You can use Async Http Client library for your remote java client in that case.
If you want to implement a PUSH behavior, then Commet is the way to go.
If there are few clients, perhaps you could solve your requirements by allowing the client to continuosly PULL changes from the server each few seconds.

Using other ports on CloudBees

I'm trying to write a multiplayer realtime game and run it on CloudBees (the client side is an applet, the server side a java web application). Is it possible to give the server permission to listen on another port? (ie so the server-side code can create a ServerSocket on that port and the client side code can create a Socket to connect and communicate with the server)
Whilst it may be possible it is quite tricky as the available port is likely to change as your app moves around. On top of this - you would need to locate the address of the instance of where your app is running (ie some kind of dynamic directory) - so kind of fiddly. The web routing layer does all this for you - but presumes http or similar (you can use "long poll" and keep a connection open from an applet - this could work in a similar way, with some work).

Is it possible to access the different ports on a web server?

I created a game and I want to put it on online. I want to buy a website (I'll probably use goddaddy to buy a domain name and use them as the web host) to use as the server to handle game play. Because I would need a separate server for each game, I would need each game's server to exists on different ports. So this leads to my question, is is possible to access these ports on my future web server? (I wrote the program in Java, so I would assume that I would access the ports from the server side by choosing a port for a ServerSocket, and from the client side by using the IP address from the website and the chosen port for a Socket)
(note: also, I am aware that it may be easier to simply use one port and run the servers on different threads instead, but I am just curious to have my question answered)
thanks a lot,
Ian
Technically it is possible to use different ports, but I don't think that a webhoster like goddaddy will let you run a java process that binds to a special port.
If you mean that you are going to create your own TCP server you obviously can create as many instances of your server and configure them to listen to different ports. But it is year 2011 now. This solution was OK in early 90s.
I'd suggest you to use Restful API that works over HTTP. In this case you can forward calls to server side of each application using URL, e.g.
http://www.lan.com/foo/login?user=u123&password=123456 - log in into application foo
http://www.lan.com/bar/login?user=u123&password=123456 - log in into application bar
In this case you need only one server (the web server) that is listening to socket (port 80).
Your server side implementation could be done using various web techonlogis (php, java, asp.net etc) on your choice.
Yes, that should work. The security manager permits connections to a different port on the same IP address that the applet was loaded from.
You can run a Java server on whatever port you want. Each server will accept incoming requests on one port.
The correct way is simply run on one port and each connection will instantiate a new servlet instance (which happens to run in its own thread) that can then service that request. You usually don't need to run separate ports or worry about concurrency, especially if all the stuff that's shared between connections (e.g. multiple players in one game) is handled through database read/writes.
Your host (GoDaddy) will have to allow you use of those ports, but if they are providing proper hosting (not virtual hosting) and given you your own IP there's no reason why you shouldn't be able to.
Your solution may work theoritically, and I like AlexR's solution. But providers like godaddy doesnt let you run a java server, on ANY port. You will need to find out somebody who does. What I found is the cost goes up from $5/mo to about $20/mo, but you get a much better (read faster) machine. Good wishes, - MS.

Categories