我在客户端使用这段代码来接收来自amazon EC2服务器的消息,但是这个客户端没有从服务器收到此消息。为什么会这样? //客户端代码
BufferedReader in;
receiveMessage(BufferedReader in_){
in = in_;/*value passed to in_ is new BufferedReader(new InputStreamReader(clientsoc.getInputStream()));*/
Thread t= new Thread(this,"receive Message");
t.start();
}
@Override
public void run() {
// throw new UnsupportedOperationException("Not supported yet.")
System.out.println("Ready to receive message from server");
while(true){
try {
String s = in.readLine();
if(s != null)
System.out.println("Server Says : "+s);
} catch (IOException ex) {
System.out.println(ex.toString());
// Logger.getLogger(tcpServer.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
//将邮件发送到客户端的服务器代码
sendMessage(PrintWriter out_,String userID_){
out = out_;
userID = userID_;
Thread t = new Thread(this,"send Message");
t.start();
}
@Override
public void run() {
//throw new UnsupportedOperationException("Not supported yet.");
System.out.println("tcpServer: Waiting to send message to client,, is there any???");
while(true){
if(outgoingMessages.size()>0){
InstructionMessage im = getOutGoingMessagesAtIndex(0);
System.out.println("tcpServer: just about to send message to client with receiver " +im.UserID + " and current thread id is " + userID );
im.UserID = im.UserID.trim();
if(im.UserID.equals(userID.trim()))
{
String s= im.toString();
System.out.println("innnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn iffffffffffffffff "+ s);
String responseString = "";
responseString =responseString + "userId = "+ im.UserID;
responseString =responseString + " # importance = " + im.Importance;
responseString =responseString + " # text = " +
im.MessageText;
responseString =responseString + " # htmlEnabled = " + im.html;
System.out.println("sentMessae to client is ^^^^^^^ "+ responseString);
out.println(responseString);
outgoingMessages.remove(im);
}
}
}
}
但客户端未收到消息。我们尝试了端口8889和1098,但它没有工作
答案 0 :(得分:0)
尝试通过调用
使用println方法来刷新流out.flush();