help on ejb stateless datagram and message driven beans
Posted
by Kemmal
on Stack Overflow
See other posts from Stack Overflow
or by Kemmal
Published on 2010-05-14T18:09:32Z
Indexed on
2010/05/14
18:14 UTC
Read the original article
Hit count: 320
i have a client thats sending a message to the ejbserver using UDP, i want the server(stateless bean) to echo back this message to the client but i cant seem to do this.
or can i implement the same logic by using JMS? please help and enlighten. this is just a test, in the end i want a midp to be sending the message to the ejb using datagrams.
here is my code.
@Stateless
public class SessionFacadeBean implements SessionFacadeRemote
{
public SessionFacadeBean()
{
}
public static void main(String[] args)
{
DatagramSocket aSocket = null;
byte[] buffer = null;
try
{
while(true)
{
DatagramPacket request = new DatagramPacket(buffer, buffer.length);
aSocket.receive(request);
DatagramPacket reply = new DatagramPacket(request.getData(),
request.getLength(), request.getAddress(), request.getPort());
aSocket.send(reply);
}
}
catch (SocketException e)
{
System.out.println("Socket: " + e.getMessage());
}
catch (IOException e)
{
System.out.println("IO: " + e.getMessage());
}
finally
{
if(aSocket != null) aSocket.close();
}
}
}
and the client:
public static void main(String[] args)
{
DatagramSocket aSocket = null;
try
{
aSocket = new DatagramSocket();
byte [] m = "Test message!".getBytes();
InetAddress aHost = InetAddress.getByName("localhost");
int serverPort = 6789;
DatagramPacket request = new DatagramPacket(m, m.length, aHost, serverPort);
aSocket.send(request);
byte[] buffer = new byte[1000];
DatagramPacket reply = new DatagramPacket(buffer, buffer.length);
aSocket.receive(reply);
System.out.println("Reply: " + new String(reply.getData()));
}
catch (SocketException e)
{
System.out.println("Socket: " + e.getMessage());
}
catch (IOException e)
{
System.out.println("IO: " + e.getMessage());
}
finally
{
if(aSocket != null) aSocket.close();
}
}
please help.
© Stack Overflow or respective owner