Servlet and serial port - java

We need to develop centralized device management based on java. So Could you tell me how to write servlet to read serial port from client with usb token?

Not easily. In order to access resources on the client outside of the protected "sandbox" in the browser you will have to do it using a signed applet that communicates with the serial port and then back to the server (through some servlet interface like a web-service, for instance)
Alternatively, you can write a "real" client application that you would have to distribute and run on the client machine. This application would, in turn, communicate with the serial port and with the server through some communication method. This could also be a servlet-based communication like a web-service.
Point is, this has very little to do with servlets as a servlet executes on the server and has nothing to do with the client.

Related

Sending commands serial port, MVC Application

I'm developing a MVC C# applications, and i need to send raw commands to the serial port, and i want to know what is the best way to do this, is there a way to do this with c#(i guess not because this code is running on server side, and the hardware is in the client side)? Or i need a Java Applet?
I've been checking this but it is for printing, would it work?
(i haven't tested it because the terminal that i want to send the commands is being delivered)
I assume you're using an ASP.NET MVC web application and now want to access the client's (browser machine) serial port. This isn't possible with ASP.NET MVC without additional client software like a signed Java Applet or other software installed on the client machine (like a service, browser plugin or background application.)
This thread may be of use:
How to read from Serial port in a webpage

How to let browser send messages to a local java application?

I want the browser to send a message to my local Java application (which is programmed by myself) when I click a button on a web page which is also written by myself using php. Is there any way I can do that?
This is the wrong way. You don't send information from your server to your local application. Your local application should grab the information from your web server.
The local Java application can implement a webserver. There is a number of libraries out there, or you can use ServerSocket / SSLServerSocket to implement it low level. The server socket should be bound to localhost in order to prevent direct external access.
You can use JSONP to communicate with this local webserver.
Pay special attention to authentication, because any website you visit, can instruct the browser to send requests to the local webserver.

How to invoke client method without using RMI

i am developing a client/server program in which i want to invoke a method of client program
through server program.
this is vnc based application in which the server will be running and listening to any arbitrary port number .... the client will connect to the server using a method which has argument in the form of ip and port number of server.
after that the server will be able to take control of the client's screen.
i want to call this method from server !!
i want to add a facility in which the client will submit a request and server will then connect to the client ..
i have heard about RMI but i want to know is there any other way available to achieve this if not pls post some good tutorial links on RMI .
RMI is a Java-only way for network programming or method calling but Web Service is language-independent. By web service you can integrate some application.
But my recommendation is using MOM systems. This type of system support two approach : Synchronous Model and 'Asynchronous Model'. In Java MOM is implemented via JMS.(look in here). JMS is an API and have several implementation such as :
Apache ActiveMQ
Open JMS Queue and etc
better than RMI, you could make a web service and a client for it :)
http://www.artima.com/lejava/articles/threeminutes.html

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.

HttpServletRequest.getRemotePort() returns different port per http request received on same machine?

I need to identify the remote ip and port of the clients that register to my service. Also, when the client web app goes down it un-registers itself from my web service.
i am using HttpServletRequest.getRemoteAddress() and HttpServletRequest.getRemotePort() to identify the clients.
but the problem is when i test on same machine i get different ports from the same client web app.
I am running JAX-WS web service on GlassFish and the Client Web App is also installed on the same container. Also, i am running Fedora 14 VBox VM.
Yes, that's correct, the port used by the connection is never guaranteed to be the same, and as you see, it varies.
The port is decided when the connection is made from the client to the server, and if multiple request are coming on multiple connections, multiple ports appear.

Categories

Resources