I have started java not that long ago, and I was wondering, if I want to make a GUI, and then I want the gui to display some data, I can't have mysql connection in that gui, it's a very big security exploit, therefore I've thought about making a java server that receives packets, and sends back data.
I know PHP HTTP callbacks are the best for this, but I really want to get into the server/networking in java.
Is there any library that offers such thing? Tutorials?
Use Grizzly, Mina, or Netty. Here's Sun's sockets tutorial if you want to learn from the ground up. Grizzly and Mina use Java NIO which is confusing to a beginner. Might want to start with the tutorial.
Out of the 3 frameworks I suggested, I've only used Netty for a project. I read Netty was lower level, and had more speed 6 months ago. It worked well for me.
Related
Unfortunately for this question, I can't really post my "Attempt" at solving this issue, because I'm not sure what the issue is to begin with, here recently I've been developing a small networking wrapper for gaming servers, me and a few friends have been testing it using C#/Java clients and it's been working out great; However I decided that I wanted to try something new and mess with the (Sortof) new HTML5. I've seen examples of games that are written in HTML5 and look absolutely amazing, an example of this would be the Runescape browser based game which has an HTML5 version. More information here.
I'm only interested in working with 2D games, however I thought that instead of using a Java Applet (Like I used to) I could learn how to do things in HTML5 and have a true web-based application. The problem isn't so much learning HTML5 as it is understanding its networking.
Currently for my server I'm using Netty, which is a Java NIO framework, however I've been studying and sources claim that HTML can't connect directly to a standard TCP socket and instead require a WebSocket. I did some searching into netty for a websocket and it seems supported, information located here.
My only question, in which I can't find any information on is sending the data in a manner that the server will be able to read it. I'm using the DataInputStream class to read data on the server side, which requires special encoding to create "Blocks" of networked data, as-well as some customized encoding for primitive data-types, and a custom encoding for UTF data-types. I wrote my own output stream for our C# client API, however with HTML I'm at a complete loss.
I can't find any information about sending data, or customizing the data sent into blocks, or anything. C# made it really simple with the use of it's BinaryWriter class, but with HTML5 I'm just at a complete lack of resources to learn from, or my google-fu really needs to be worked on.
I am trying to make a little game in java and it needs to ask a server to verify it's data.
I'd like to use heroku because I want to write the server in ruby with sinatra but I don't really know a good way to get websockets working with java.
My last bet is just to use normal sockets within ruby but because of the way heroku does it's port routing normal socket apps don't really work.
The answer to this question here makes it sound like there is a way I can do it using http requests.
Is there a way to do that or am I running around in circles?
Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I want to create simple server having low load. The goal is to give a few javascript clients access to some functionality implemented in Java through WebSockets. I seek for best library to use for that - it should be simple, robust etc. Now I consider 3 alternatives
- jWebSocket
- jetty
- netty
What is the best? Or may be something else?
Thanks in advance
I'd go with proven Java servlet servers: Jetty or Resin. The have both been extended to handle WebSockets:
Jetty WebSockets
Resin WebSockets
My personal choice would be Jetty, as it's very simple to use and I've been using it as embedded server in several projects.
There are also some new kids on the block like Atmosphere and jWebSocket, but for servers I prefer to go with a proven solution. Jetty and Resin are also generic Servlet servers, so you can go with one product for all your serving needs.
jWebSocket now includes the Jetty 8.0 engine including SSL and includes many nice-to-haves on top of it. It provides cross-browser and cross-platform compatible clients even more mobile apps e.g. under Android, Symbian and BlackBerry. The server can easily be extended with plug-in and already includes lots of them (e.g. for Authentication/Autorization, JDBC, SMTP, XMPP/Jabber, RPC, Twitter, Filesharing, Chat etc.). Just check it out... http://jwebsocket.org. Looking forward to your feedback.
Regards
Alex
The PlayFramework! is the other very good option.
FYI, Atmosphere run on top of Resin, GlassFish and Jetty. Atmosphere free you from being stuck with one server by giving you Websocket portability amongst Websocket server. It also offer a client library that can be select the best transport in case websocket isn't supported by the browser. So you can't compare Atmosphere with Jetty or Rsin
Take a look at Atmosphere. Here is an article about websocket and atmosphere.
While I value the implementations of JWebsockets and Autobahn a lot, I prefer Atmosphere.
Ramp-Up::
Ramp-Up time is low. Francois Arcand puts a lot of effort into testing and examples, helping everyone to achived quick wins. (And I have no clue why he's able to respond so quickly to any architectural questions I rise. Impressive.)
Maintenance Perspective::
To me, maintainability is fundamental, if a software goes beyond major release version 1.0.0. The project is maintained at a top Maven-POM level with a properly constructed hierarchy. It prevents library incompatability. Libraries are reference at the correct level. That is well done.
Technical/Functional Perspective::
It offers a Java SE client library (wasync) that can either do native websocket communication (onMessage) or build on Jersey REST annotations (#Path). Subsequently this makes it as simple as it gets with the benefit of maintaining an open connection for subscriptions and the popular remote procedure calls (RPC) paradigm. It is a common attempt to merge those two paradigms. See also http://wamp.ws/, which heads for the same approach. Also, the library offers to establish QoS properties like robustness (e.g. in case a client disconnects) and reliability (caching undelivered messages). That is great for professional software to harness.
Maybe you should try Bristleback Server? Using Bristleback, you may choose from several WebSockets engines, like Jetty, Netty and Tomcat. You can have standalone server as well as web application that uses WebSockets (Jetty and Tomcat 7). Bristleback uses Spring Framework. If you have worked with web frameworks like Struts, Stripes or Play!, it will be very easy for you to start. Of course, Bristleback has its own JavaScript client library for even easier development.
Full disclosure: I am one of the co-creators of Bristleback Server.
I would also add vert.x to the list. It can server Websockets and SockJS (websocket emulation when the browser doesn't support them).
Update:
Undertow http://undertow.io also supports websockets.
Follow my blog. I'll be ready for release sometime in the not too far off future. Light-weight has been emphasized through the whole thing - but it's also fast. I don't know yet how well it will ramp up to higher loads. But I've been running the demo for a while now with relatively low load and what I have has been working well. (I'll test heavier loads later and make sure that it can be ramped up.)
http://highlevellogic.blogspot.com/2011/09/websocket-server-demonstration_26.html
If you are looking for infrastructure around message management, user grouping ("rooms"), and data synchronization ("shared variables"), you might want to consider Union Platform:
http://www.unionplatform.com
[Full disclosure: I am one of the co-creators of Union]
Why don't you just write your application on an open standard like JMS, and let the clients sit on the JMS bus as message clients?
The whole point of websockets is to bring any native TCP protocol directly to the client instead of converting it from your back end to http request/response.
Your back end services would talk to a JMS broker like ActiveMQ, and your clients speak AMQP in the browser via a Javascript API that looks just like the JMS API in Java. All you need for that is a websocket gateway, for example Kaazing has such a gateway, all it does is route your JMS TCP traffic out to the web clients over websockets. They also provide fan-out so that you don't overload your JMS bus, i.e. you just use a handful of connections to the broker to offload a million browser client connections.
The bottom line is that you don't need to tie yourself to any specific platform. Stick with standards, that way you have 100% freedom to swap out components as your environment changes.
I have made a Java Swing application. Now I would like to make it a Client-Server application. All clients should be notified when data on the server is changed, so I'm not looking for a Web Service. The Client-Server application will be run on a single LAN, it's a business application. The Server will contain a database, JavaDB.
What technology and library is easiest to start with? Should I implement it from scratch using Sockets, or should I use Java RMI, or maybe JMS? Or are there other alternatives that are easier to start with?
And is there any server library that I should use? Is Jetty an alternative?
Given that you have the application already, perhaps the simplest thing to do is to identify the interface that you require between the client and server, and first of all to refactor your application to use that interface to talk between the back-end/front-end within the same process.
Then you can start to split this apart. A simple solution would be to split this apart using RMI (since you're talking Java objects and have Java method calls). Spring contains useful tools to simplify/automate the RMI exposure of interfaces.
For the notification requirement, a simple UDP multicast (or broadcast) would suffice.
Note that as soon as you split your application up, you have issues re. maintaining consistent views of data, managing timely updates, handling cases when the server is down, possible loading issues when you get lots of clients etc. In a sense, splitting the application up into a client and server is just the start of a new architecture process.
Mina is a good choice as a network application framework for building a simple server for this purpose - it's a much better option than using raw sockets.
http://mina.apache.org/
If you really need an application server then you could take look at JBoss. It also provides a remoting component (as an alternative to something like Mina):
http://www.jboss.org/jbossremoting
You probably won't have much need for Enterprise Java Beans though. In most cases a simple POJO based framework is more than sufficient - you could tie this altogether with a dependency injection framework such as Guice:
http://code.google.com/p/google-guice/
or Spring. Keep it simple, don't use a J2EE server unless you really need to. Hope that helps.
This is much of what J2EE does, but it's a whole new learning curve because they have pre-solved many of the problems you will run into and many you may not and therefore add on a lot of new technologies.
But at it's most basic, J2EE answers just that question.
I worked in a project like this. We implemented Client-Side Swing and Server side with J2EE. We used EJB,Stateless beans and Message Driven Beans.Also I have been in a device tracking, management project. Our clients were trucks+Swing users and We have used Servets+TCP/UDP,Apache Mina framework to handle and keep connections.
I have been working in Java Swing Client/Server applications for almost 3 years. I would suggest you to go for RMI/EJBs. The initial application that we developed was doing this using RMI/EJB for client-server communication with WebLogic being the server.
But we later found out that there are lot of "browser-like" features to be included to the application such as session-timeout etc., So, we used the BrightSide Framework which wraps the RMI calls through HTTP. One more enhancment we made is that we replaced Weblogic with the open source JBoss server.
The wrapping of calls with HTTP will become very handy and you can make your swing applications really rich. Later, when the situation demands for you to use a website strictly, you can deploy your swing using jnlp.
Hope this helped.
I'm writing/porting a C++ HTTP event server to Java. I'm wondering what are the best paradigms for implementing comet with Jetty, Tomcat, any other server, or natively.
Threaded
Continuations
NIO
Servlet 3.0
Scalability is an absolute must as I'm developing a new protocol that uses up to 3 concurrent connections per client.
Any help is appreciated.
PS: If possible, I would love to also see some sample code or tutorials..
We've had a lot of success with Caucho Resin's LongPoll features (the majority of the data to our UI comes in over Comet). Caucho has also added support for WebSockets, so if you have an HTML 5 client you can benefit there too.
On Linux they have some custom JNI code that talks directly to epoll, which allows the server to scale well.
Glassfish has native comet support and I thought there was WAR for comet support in tomcat from the Glassfish team. Jetty also seems to be leading the crowd. Am I misunderstanding, but why are you trying to re-implement comet in a Java app Server?
Or you can drop Comet and go WebSockets: http://www.jWebSocket.org
I've been looking into Comet myself the past couple days. My company uses Tomcat in development and WebLogic in production. We'd like to incorporate Comet without shaking up our existing application. I've been impressed with Atmosphere's APIs. It focuses on the server side, allowing for portability while taking advantage of native server features like NIO. They seem to be putting out updates every month.
https://atmosphere.dev.java.net/