I want to make real time chat and I want to use Java SE with websockets on server side and html/JS on client side. It's very hard to find websocket library that works with Java SE (or I'm looking at wrong places). Is using Java SE for websocket application at all good solution?
I followed this tutorial:
https://spring.io/guides/gs/messaging-stomp-websocket/
but imports are not working well for me:
The import org.springframework.boot.autoconfigure cannot be resolved
Is this because Java EE is required?
Please give mu URL of some (working) tutorial/youtube video. I'm using Eclipse and I'm not too experienced with it, so "for dummies" rated article will be more suitable.
I know that question is not very precise, but I'm desperate - wasted days, tried few different libraries, but nothing works, so I just need to get it running.
Jetty is a very lightweight library that helps JavaSE developer with all kind of network communication for client and server. Chat applications have been the 'hello world' for such a kind of library. I would recommand any good tutorial on this (just type websocket chat jetty in your favorite browser). If your main goal is to LEARN how it works, instead of copy/paste, I would recommand a simpler tutorial like this one.
Related
I am trying to add a voice / video chat feature to my web-based chat application developed in JavaEE.
I have not found any tutorials on how to achieve that with both Server and Client written in Java (no javascript allowed).
Is there any tutorials that can help me (using websockets for example) ?
You might check out the github project Jitsi. I don't know exactly what tech they are using, but there is a Java version and the code is available for inspection. They may have a forum. I have only taken a cursory look but was reminded of the project by your question.
Over the weekend I set up all the networking for a game I was making. I was basing it off this tutorial: GamesFromScratch.com Basic LibGDX Networking. It said that it only supported TCP but I was okay with that since I could figure something out and there was a bunch of material online on how to make real time games without UDP. After I finished, I tested it on desktop, android and then on HTML5/GWT. Desktop and android worked but GWT didn't. I did some research and found that Gdx.net does not support GWT, the article didn't warn me :/ Basically now I am trying to find an alternative solution that will work with ALL libgdx platforms.
I looked into Websockets with Socket IO. Here are the Java libraries I found for the: Client and Server. The server library says it works well with the client one which is reassuring. It seems like a good solution but I have a few questions:
- Would the client library work on all platforms? It seems that it would work on android and desktop since they don't have to convert to another language but what about GWT and iOS? And not only just work, but also be able to connect to the server using the server library.
- Is there anything I need to watch out for when using websockets?
Thanks.
EDIT: I did a little bit more research and I found Jetty. I looked around and it seems to be GWT compatible, I just need to know if it is also iOS compatible. And could I use Jetty as my server api also?
I did it. I did a lot of research in the past few days and I finally found this post on stackoverflow.com that told me about 2 great libraries including one I could use with the client that supports GWT.
It works great, the only thing is that I will have to use 2 WebSocket libraries for the client, one on html and another for all the other platforms but that's okay, at least it works.
The libraries are: Client and Server.
you can use Kryonet which provide network for PC, Android and iOS(not tested). On this library you can build server side or client side app.
In GWT you have WebSocket and you must use other library to connect with server.
When you start game, you can inject right implementation client for GWT can be example: gwt-websockets and kryonet for other platform.
Next, you must change kryonet default serialization implementation by own, supporting json. In my project i use LibGDX json serialization.
Currently, i don`t have support for gwt but i will work on it in near feature.
Jetty in my opinion is too heavy for client and isn`t simple so much. But witch Spring, you can easy create server service based on REST or http communication.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
I'm really starting to get a hang of the client-side Java programming, and from what I understand Java is great for developing stable server sides for large amounts of traffic.
The problem is that I'm completely new to server development, so I don't know where to start or where to look for information, despite Java's good documentation.
More specific questions:
Do you know any good, non-specific tutorials for server-side Java? I've seen some tutorials for Google's Cloud Platform and Netscape, but I don't want to be dependent on their infrastructure.
Is the common practice to develop your code in Eclipse and then "ship" it to your server? As I said I've never done server-side development and I've only tried learning a little node.js.
Thank you in advance, I hope these questions aren't to wide-scoped.
I would suggest you to start with a simple setup like you already told us: Eclipse + let's say an easy to use tomcat.
If it comes to the server side you need to create a Servlet which allows to access other application data from your server in a format which you define or let's say you + the clients define. I would suggest you to start with something you will be familiar like Json. For this I have a little "starting point" for you.
Clone that simple example for a server-side application:
https://github.com/DominikAngerer/java-GsonJerseyProvider
It already provides you a simple structure for Json which is used by a Framework like Ember and also you can easy modify the structure which is defined there.
Is the common practice to develop your code in Eclipse and then "ship" it to your server?
Yeah it's totally common to do that. Write your Server Side code and export it as .war - tomcat or jetty for example can simply deploy them and you will be able to run them on these application server.
Do you know any good, non-specific tutorials for server-side Java? I've seen some tutorials for Google's Cloud Platform and Netscape, but I don't want to be dependent on their infrastructure.
I really love to work with Jersey - It's really a to understand the code you will write. Maybe try the example provided by IBM developersworks: http://www.ibm.com/developerworks/library/wa-aj-tomcat/
For the beginning it may be a little of a overhead but after you tried the example (it should be running right away) I think you will get the idea of how to create a simple backend system with java.
If you want a complete environment out of the box, you can try:
Netbeans EE IDE:
It contains a GlassFish server and the SDK preconfigured, glasfish is one of the most used open source application servers. Here you can find tutorials from the Netbeans page.
JBoss Developer Studio: is another very used IDE that includes a JBoss server. You can find tutorials from this one here.
I would sugest to start with GlassFish, as it is very easy to use and configure.
Take a look at JavaEE. I would start by learning how to create simple JSP pages with Eclipse + Tomcat (create a "Dynamic Web Project"). After that, check out Servlets and be sure to understand HTTP. After that, I would get an overview of JSTL and other Java EE components. DZone has a nice refcard giving you an overview of the Java EE 7 components.
After that, you should be good enough to move on to a framework like Spring or Struts. Alternatively you can perfect Java EE fully learning it's more advanced components like CDI(context dependency injection) or JAX-RS and JAX-WS(web services). This document should give you an overview of how to configure a servlet container in eclipse: http://www.eclipse.org/webtools/community/education/web/t320/Configuring_an_Application_Server_in_Eclipse.pdf
As for tutorials, check out Oracles JavaEE 7 tutorial at: http://docs.oracle.com/javaee/7/tutorial/
Alternatively, if you do not like the styles and patterns used in Java EE, there is a non-Java EE framework called the Play Framework (http://playframework.com) it gives you the option to develop your application using either Java or Scala, and uses MVC architecture.
If you want to learn server side programming with JAVA, I recommend to start working with Eclipse. Almost all developers whom I know are using one or another IDE, most of them are using Eclipse for J2EE.
There are plenty of tutorials available on how to setup eclipse on your local computer. I personally read many tutorials when I learned it, you can google it.
http://www.apekshit.com/t/11/Writing-JAVA-programs-in-Eclipse
http://www.apekshit.com/JSP-Tutorial-for-beginners-with-Examples/c/21
I found these 2 that might help you to achieve what you are looking for.
I plan on making an instant messaging app on Android and iOS, where you can chat to other people with the app, along with some custom features.
I’m going to use the XMPP protocol, and make a custom extension for it. I plan on making a Java application running on Amazon Web Services (AWS) so it's scalable.
After researching server options I’ve decided to use Apache Vysper.
However, I’ve never made a proper Java application before, and have never used XMPP, AWS or Vysper – so I’m rather reliant on good documentation :-)
The Apache Vysper project is very new and so the docs are a bit sparse. I was wondering if I was missing something, should I be using the general MINA docs as well? Are there other resources
elsewhere I don’t know about?
“Apache Vysper can run stand-alone or embedded into another
application.”
To be honest I’m just as lost when it comes to working out what to use to make a Java application anyway. Do you know if the AWS Java SDK has everything I need to make an application to use on AWS? And then is it a simple matter of integrating Vysper into this? Or do I need to make a Java application using something such as the Spring framework?
Thanks for taking the time to help me. If you know anything that could clarify the situation I would really appreciate it :-) --and sorry be being a bit useless, but hey, we've all got to start somewhere right ;)
First of all, as the founder of Vysper I apologize that the documentation is lacking completeness.
To answer your question(s).
Most Java applications bring their own ready-to-go start scripts with them.
Vysper is no exception. You get the pre-packaged download here:
http://mina.apache.org/vysper-project/downloads.html
Ok, before running it, you need to have Java installed, whether you're on your own machine, AWS, a server or a virtual machine anywhere else. Get it from Oracle, or use the package management of your Linux distribution. Make sure that after installing Java, you can execute "java -version" on the command line and you are all set.
Then, unpack the Vysper download, change to the bin/ directory and execute "run.sh" or "run.bat", depending on your OS.
Please note that support for Vysper - besides here on StackOverflow - is available on the MINA user mailing list here:
http://mina.apache.org/vysper-project/mailing_lists.html
I am really really having hard time to create simple "Hello World" Web Service in Java. If you exclude several mobile Android mobile apps I have done, I am pretty new to Java environment.
First I tried Axis2 and that simply doesn't work out of the box. Fresh installation of Eclipse, Tomcat 6.0 and Axis2. Tried sample test app and it failed miserably. You can read about it here. My conclusion is that Axis2 simply doesn't work (maybe it used to work). I will try to go back to install older versions, maybe one will magically start working. I have to modify some old project at work that was using Axis2, so that's why I have to stick with it. I would hate to have to migrate to some other tool.
Then I ran on Oracle article Getting Started with JAX-RPC and I was thinking, cool, let's try that. Well, I just managed to get pissed off. After getting half way through the article and trying to write some simple test web service I realized that their code examples are poorly written. Missing brackets, wrong references, missing explanations, etc...
First of all, an interface should extend not implement. Am I right?
public interface SunRegPort implements java.rmi.Remote {
Also, this doesn't exist:
import java.xml.rpc.server.ServiceLifecycle;
But this does:
import javax.xml.rpc.server.ServiceLifecycle;
Well, I don't feel competent to criticize too much (cause of my level of knowledge about this subject of course), but after all I am suspicious that this article is complete JUNK and therefore I am not able to follow it.
Please somebody tell me that I am wrong and if anybody has some advice or link to some How-To page that talks about web services, I would appreciate.
Thanks.
The terminology Web Services is pretty vague. In Java, the modern and reasonably easy way to do this is by annotating classes.
I would recommend that first, you decide whether you want to implement:
SOAP Web Services -> look at JAX-WS
REST Web Services -> look at JAX-RS
Once you have chosen the "type" of Web Services, choose the library that implements the specification.
The Wikipedia entries list a few of these implementations. Apache CXF (complete but a beast), Jersey (popular) and Restlet are very common choices. I personally like the JBoss implementations as well for JAX-WS.
For JAX-WS with Apache CXF, here is a quick start tutorial that looks pretty good (untested)
For JAX-RS with Jersey, try this
Unless you have strong reasons to do otherwise (for instance you need to call an existing system), use REST which is simpler and leaner.
I would recommend you to check out the CXF project by apache. It's quite easy to use and should help you to set up a webservice.
There is a nice guide to Hello world set up.
http://cxf.apache.org/docs/a-simple-jax-ws-service.html
If you're still interested in giving Tomcat a shot, here is a tutorial on youtube of making a very basic "Hello world" example using Eclipse. It leaves a lot to learn; but it looks like it will at least get you started.
FYI, the version of Eclipse used is slightly outdated. So some of the menu options may not be exactly the same:
http://www.youtube.com/watch?v=EOkN5IPoJVs
Also, the meaning of "Web Service" can be subjective. So, to be specific; this just shows you how to get a basic HTTP endpoint started on your local machine.
If you are not tied to Eclipse, give NetBeans a shot. I think it's much better for Web Services in Java.
Web Services are most widely implemented examples of Service Oriented Architecture (SOA). A service contract is defined with the help of SOAP and Web Service Definition Language (WSDL) and that is published for other applications to use.
In this article we will see how we can create web service and web service client in java.
http://www.opencodez.com/java/how-to-build-and-deploy-web-service-and-client-in-java.htm