简体   繁体   English

未从服务器收到响应

[英]Response not received from server

I am using this piece of code at my client side to receive message from amazon EC2 server but this client is not getting this message from server. 我在客户端使用这段代码来接收来自Amazon EC2服务器的消息,但是此客户端未从服务器获取此消息。 Why is it so? 为什么会这样呢? //Client code //客户代码

     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);
                }
            }
        }

//Server Code to send message to client //服务器代码向客户端发送消息

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);
            }   
                }
            }
        }

but message is not received by the client . 但是客户端未收到消息。 We tried port 8889 and 1098 but it not worked 我们尝试使用端口8889和1098,但无法正常工作

使用println方法调用后,尝试刷新流

out.flush();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM