Java how to deploy socket server web application? - java

I wrote an application with front end in js and back end in java. It is supposed to be a socket application. In js I use standard socket javascript client. In java I use classes from packages javax.websocket, so the essential class has the annotation #ServerEndpoint("/server"). I deployed my app on openshift and only client is working. When I try to connect to the server(url looks like ws://address.of.my.page.on.cloud/server) I get the console alert in firefox that the connection with socket server could not be done. I guess maybe openshift isn't suppose to handle sockets but I could not find any servers that provide such possibility for free. Are there any out there? Or maybe I am doing something wrong?

Related

Tomcat websockets and separate java process communication

I have a tomcat 7.0.53 server running for the purpose of communicating between java and the website through websockets. I wrote the website script as well as the websocket server java code and they communicate and work correctly. However the information I want passed to the website is from another java program running in the background on a Linux machine. The problem lies however with that when I try to pass messages into a sendmessage type of function on the websocket server java code, it thinks that no sessions are open to send the websocket message to even if I do have the website opening waiting for a message from the separate java process to be passed through the websocket server. I found out this problem arises since I have to make a new instance of the websocket server when passes messages from my separate java process into the websocket server sendmessage function and thus there are no websocket sessions in that instance. I am stumped as to a way around this problem other then to making a socket between my websocket server and the other java process running which will be messy and want to avoid. Does anyone else know anyway else this can be done with communicating a separate java process with a websocket server for tomcat, or is this just impossible to do without making a socket?
I'm not entirely sure I understand your question. Could you share the code you are using to provide more context as to what you are attempting server side?
I believe you should be able to create a websocket client endpoint from the second java program. You can find examples of java websocket clients in the web such as the following:
http://www.hascode.com/2014/11/creating-different-websocket-chat-clients-in-java/
hope this helps

How can i host java udp program for my android application?

i am developing an android application in which the server side execution is done using a simple java udp program.i want to know how i can host this application because i need a static ip server to run the java program.can i run my java program in a server.is it possible if yes how?
You'll have to write a listener in some language (PHP, Java, Etc.). As for a static ip address, you can also look at a dynamic ip redirection service like no-ip;
http://www.no-ip.com/services/managed_dns/free_dynamic_dns.html
You can use a personal machine thats always online, or you can try to use a shared hosting plan that allows you to have a listening port open. A web service will likely be easier to work with than having some custom UDP/TCP connection.

how to launch java socket-server on remote server

OK, I'm new to server-client applications, and i need some basic information, so forgive me if my question is not clear...
I want to make a chat application that would function like this:
Client A sends information to server, server sends the same information to client B, and vice versa... Think of it as of a simple chat program.
All communication is done through sockets, so i would have a server socket application, and a client socket application... I want my client application to be on my PCs and server application to be on a remote server ( it would be hosted on some free hosting websites).
My question is how do I start that server application on that remote server?
Thanks in advance!
If you are just trying to make a chat client, I don't think you would need an intermediate server. Just connect two machines using server and client sockets
SERVER:
ServerSocketChannel serverSocket;
serverSocket = ServerSocketChannel.open();
serverSocket.socket().bind()
serverSocket.socket().accept()
CLIENT:
SocketChannel clientSocket = SocketChannel.open();
clientSocket.connect();
Of course you would have to use the bind and connect functions properly. Read up on their API's
The remote server can be started manually. (If you do not have access to remote server or if you are hosting your server on some third party infrastructure, then they might have a way to do it.)
To be able to start it remotely via some program, you again need a server on the remote machine that listens to this kind of requests.
Usually, you want an application that is running all the time at your hosting provider (like a web server or perhaps inetd) to start (or embed) your application. The details will be determined by what your hosting provider provides.
If you're using plain sockets, you should look for some remote server with SSH login. You're able to start your application on the shell then, sth like:
java -jar yourapp.jar
Free hosting websites are rather targeting customers that want to host their website. In my opinion that is not the best choice for hosting a socket application.
For developing purposes, I'd stick with the local machine for the beginning. Running/testing server/client connections on the same machine is much easier as you don't have to work on two different machines, copy code, etc.
This tutorial is relatively short, but fully covers basics of Java networking. And it is right about simple chat.

writing desktop application for connecting with server

I'm working on a server client base "Desktop Application". And what I want to do is this,
Client application sending some request code to server through internet(oh yes, these connections must be secured). and when server application gets this code it will again do some work and gather some data.
And then server application will return those data again to the client application.
As I am new in this, I need to know, what kind of tools to use?
Is eclipse good for that?
Where can I find good examples for writing client?
Where can I find examples for connecting client with server side?
I'd recomend checking out apache httpclient it really helps when dealing with web APIs.

Java jar application and java web application communication and implementation

I have a multiplayer game server application written in Java which connects to player clients when they join the multiplayer game via a socket. The server application (a JAR running in the JVM) is listening to a port (e.g. 9999) for incoming connections from clients.
I want to add a website to minitor the entire project which contains information taken from the running game server(s). One way would be to open a socket from the site (a PHP socket for example) to the gameserver (Java) and implement a custom protocol for taking data from the server. But that method is time consuming as I need to add support for each type of datum I want to pass to the monitoring website.
I was thinking if there is a way to write the site in Java and simply communicate with my gameserver via a direct link. RMI would be a solution I assume since both my JAR and my WAR can communicate through it, but isn't there some better way to build both the web application and the gameserver application inside the same JAR file? So that when my gameserver runs, the web application runs too?
this looks to me as the fastest way to have an admin console. Just transform your server into a war application which contains both your game server with an open socket for clients and your administration pages. To start your server simply drop it into a tomcat.
A cleaner approach which does not require some self-created protocol would be to have your server use mbeans for all key objects which you would like to admin. But this needs some coding.
Cheers, Sven
You should have an embedded web server in your game server. Try Jetty (http://jetty.codehaus.org/jetty/). It's quite easy to embed in any java application.

Categories

Resources