Communication between Java Swing Application(On client side) and server - java

What are the possible ways in which Java Swing Application which is running on client side can communicate with server?
I've read that JSP can be used in web pages to communicate between server and client.But, is it possible to use JSP with Swing application? if so, how? It would be helpful, if it is demonstrated with simple login form. Thanks.

Any client-side application, whether it be a java swing app or otherwise, can certainly communicate with any server (assuming no network limiting architecture -- firewalls and whatnot). Your options are numerous
Raw sockets
Any one of the myriad of network protocols.
HTTP/HTTPS
FTP
SCP
et. al.
It depends on what protocol, services and applications are available on the server to connect with.
HTTP/HTTPS is very common. You'll need to manually create HTTP requests and send them to the server (assuming the server is a web server).

Related

Web cilent and server communication throught firewall

I want to create a web application, which is divided into two part one is client and another is server.
Client:
Client part is on the shared server.
Client is the GWT Application which only use to display data (containing only ui elements and ui events).
Client application is used by server to view and present it's own data.
Server:
The server is the simple java web service (restlet).
The server is reside behind the firewall.
The server contains actual data.
There are N number of servers.
Server does not contains any view if server wants ro view data it will use the gwt client application.
Every server uses same gwt application to view it's own data.
Note :
Client does not contains any address of the server. server will send the request to view it's data.
There is no firewall inbound exception on server firewall to access server data from out side client
I need to communicate client and server through firewall, Is there any architecture or design pattern to implement this type of application?
I don't think that the firewall can bring new restrictions to a GWT application compared with other types of applications (clients).
In case you have the GWT client on one server which makes calls to a different server you might have some issues due to same origin restriction.
This can be resolved in several ways:
- your GWT application has a server-side part which calls the other servers. And your GWT client makes normal RPC / JSON calls to the GWT server side (on the same server).
- in case you want to make directly the call on the different server from your GWT client you can use JSONP or the restygwt library.

Sharing a configuration between java client and server applications

I'm building a java client server application (both are JSE), here a quick description.
Server
The server interact with an external system receiving "requests" and providing "responses" to these requests via TCP/IP.
The content of the "response" depends on "rules" described into a "rules deposit".
Client
Clients are Java applications connected via HornetMQ to server.
I have multiple clients that (not simultaneously) can change the "rules deposit" to update/change or correct the response behavior.
My question is: how I implement this shared "rules deposit"? Are common frameworks I can use ?
Some notes:
I cannot use shared file
I'm not obliged to use HornetMQ
I prefer not to use Database RDBMS

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.

how do i send data from a webpage to port in web server?

which is the best method to send a numerical value data from a javscript webpage to a web server port.. i have a server socket program running on the server and listening to port 5000.
i need to send data from a webpage to the port? which is the best method?
the scene is this.
i have a C socket program running at a web server hosted in my laptop using XAMPP.
it is listeing to a port 5000 and also i have my ip address. in the web page,
i am running a javascript and when the user presses any of the arrow keys i need a value to be sent to this port.. like up -1 , down -2 etc ...
There isn't currently any way to do this in a portable fashion. Some browsers support the WebSocket standard, which gives you some limited access to sockets, but this isn't currently available in any common browsers other than Chrome and Safari. The Flash player supports a separate XMLSocket protocol, which you can also use if the Flash plugin is available. However, neither of these protocols supports raw access to sockets -- both require some initial negotiation and packet framing.
Because your web server is running on a different port than your socket program, the Javascript in the browser is restricted from making requests directly to the socket program because of the Same Origin Policy. However, there are various ways to get around this restriction. Alex Sexton has a lengthy overview of all the different ways of doing this. However, all of those ways require that your socket program be running the http protocol also.
Socket.IO seems like a perfect fit for what you are trying to do, but you'll probably need to ditch your C program.
The only way to open a network socket connection from a web page is to use a Java or Flash app to make the binary socket connection. You could then use java script to pass the data to the app which would connect and forward it to the server.
Alternatively you could use some server side code and AJAX to proxy the connection and forward the data.
The second option doesn’t rely on any browser plug-in being installed and I think would be easier to implement. It would also be able to forward to a port that is not on the web server itself as it wouldn’t be subject to browser security restrictions.
I guess making one ajax request to required port on a server... can solve the request.

Message to a client from the server

I have to design a client/server system emulated on a website running Ruby on Rails that should work like this:
a page is requested by a web browser and once it's opened the server can push messages to it
I know this is not possible "naturally" but I was thinking of a sort of "java applet" that is running on that page, listening on a port for messages to be sent by the hosting server. This should be done opening a sort of a socket that listens on some port where the server can connect to send its messages.
Can this be done? Do I have to develop a java server thread or can I simply address the client applet via it's ip address and port and use any web service connection from the server?
thanks,
Luca
Comet is definately what you want. Depending on your needs, you can host your own comet server, or use a SaaS solution, such as WebSync On-Demand (disclaimer: I work there). Using the SaaS stuff, you get server-push capabilities without having to actually run your own comet server.
The easiest way to do that is to use Javascript to emulate the push mechanism. Polling in regular intervals using AJAX is sufficient in most cases. Have also a look at Comet.
An alternative to using a java applet may be to use a combination of javascript and an approach known as Comet. In a nutshell, Comet is a way to enable server push over HTTP. I'm not really a ruby on rails guy, but a quick google search for ruby on rails and comet nets a fair amount of useful information.
have you looked at juggernaut
If you want go the applet route, you need to make the connection from applet to the same server where the web page is served. The applet can't listen. Once the TCP connection is established, it's a 2-way channel, you can pull or push as long as your protocol allows it. This is how it's done with most Applet-based chat clients.
More and more people are simply using long polling in Javascript. It's pretty involved to get a reliable long polling system running, I would suggest you to use a framework. For example,
http://cometdproject.dojotoolkit.org/

Categories