2

I have created a Socket Server application that will accept Client connections from other computers on the local network. This is application is run from a public static void main method. and is a very standard java application.

I have also created a web service that runs on tomcat, it also uses java. The web service will http post accept request from any internet connected device.

Once the web service receives a request I would like it to send instructions through the socket server and send some data to the client connected.

I would like to run the socket server applicaiton within the web service so that the web service has access to the socket server without having to connect as a client.

What is the best way to run a standard java app so that the tomcat server will start the application when it starts up? should i run it as a servlet or is there a better way to have the web service access the socket

Russell Milburn
  • 109
  • 2
  • 9

1 Answers1

2

An application opening its own server socket within a proper application server is pointless and possibly counter productive IMO.

Think about it: Tomcat is probably running on port 8080. Your application is hypothetically going to be running on port 9080. What port do you think clients will need to connect to, to consume your service? And if you answered that correctly, what service/benefit are you then expecting Tomcat to provide you, if your clients are in fact, not going to interact with tomcat at all?

You don't need a (full) application server to run your own personal server. You have the option of:

  1. a Java web service without a web application server, which lets you deploy a full JAX-WS webservice within the vanilla JSE, no application server required

  2. Using the jdk's embedded HTTP server to process your requests

  3. Deploying your standalone application as a windows (or other OS) service

Community
  • 1
  • 1
kolossus
  • 20,559
  • 3
  • 52
  • 104
  • I might not be explaining my self correctly. I have two separate clients. Client A is an Android device that calls to a REST Web Service (Jersey Based). Client B is a stand alone Java Client run on linux connecting to a socket server application. If the android device calls the REST web service, I would like the web service response to the Client A as well as to push a command the via the socket server to Client B. – Russell Milburn Sep 16 '14 at 11:30
  • 1
    @RussMilburn - yeah, you weren't explaining it clearly before. You can't force a message on the client, unless your client is running its own service (by whatever technology: websockets, web service, jms endpoint etc), that will be listening for messages – kolossus Sep 16 '14 at 17:22
  • I have managed to sort this out. I have had to run my socket server as a separate application. the web server has a instance that is set up and access by the context file and i am able to send a message to client B, thank you Kolossus for your help – Russell Milburn Sep 17 '14 at 09:34