客户端组件正在将数据(文本)写入端口,而服务器组件正在从同一端口读取。直到这一点是成功的。
现在服务器组件正在从端口读取,然后将这些消息放入Active MQ。 在这里,我面临的问题如“java.net.SocketException:Connection reset”......
服务器 - 组件代码是:
public static void main(String[] args) throws JMSException,IOException{
try{
String input4mClient="";
ConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_BROKER_URL);
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("QUEUE_PORT_2_Q");
MessageProducer producer = session.createProducer(destination);
ServerSocket ss=new ServerSocket(6666);
while(!input4mClient.equals("stop")){
Socket s=ss.accept();//establishes connection
DataInputStream dis= new DataInputStream(s.getInputStream());
input4mClient=dis.readUTF();
System.out.println("at line");
System.out.println("pushed data is..."+input4mClient);
TextMessage message;
try {
message = session.createTextMessage();
message.setText(input4mClient);
producer.send(message);
} catch (JMSException e) {
System.out.println("exception at send"+e);
}
}
try {
connection.close();
} catch (JMSException e) {
System.out.println("exception at close"+e);
}
} catch(IOException e){
System.out.println(e);
}
}
注意/我在这里观察:
提前谢谢你们。
答案 0 :(得分:0)
需要向客户端应用添加休眠,以便服务器可以将消息推送到Active MQ。