简体   繁体   中英

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. 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

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

out.flush();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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