문제

I have this simple java function that is listening to one IP, using sockets:

void main()

(...)


Socket client = new Socket("192.168.9.2",63333);

DataOutputStream out=new DataOutputStream(client.getOutputStream());
DataInputStream in=new DataInputStream(client.getInputStream()); 

while (userInput == 1) {
      System.out.println(in.readLine());
}

(...)

And it works fine, but the problem is that I have to install it in WAS 7.0, and execute the main function one time, to start the process.

How can I do that in WAS 7.0??

Regards,
Pedro

도움이 되었습니까?

해결책

As per Java EE recomendations, you should avoid opening sockets in a container. If you want anyway, you need a way to start this, you have several options.

Create a EJB Session Bean with a method that you can invoke remotely (RMI...) and put the stuff in this method.

If you want to start automatically with the WAS, you can use the EJB Timer to schedule the execution of the task.

You can also create a Servlet that upon invocation do this stuff.

You should consider starting a thread to manage the socket, but the thread should be capable of stopping by itself, when a condition reaches like the while (userInput == 1).

This sound strange to do in a Application Server like WAS, but you can do that.

We do some similar tasks in SAP XI by creating a Session EJB that starts several threads to manage client sockets.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top