简体   繁体   中英

Java SE Socket Input Stream does not get response

I have created a ServerSocket binded with a port in my application. I distribute this application to the connected PCs on the same network. I can post a request to any of the PC where the application is installed, using this port. Now the recepients can receive the messages, but when they send the response back to the requesting PC, the Input stream never receives the message. Is there a way to do it. I do not know any thing about URGENT TCP messages. I enabled it but I do not know how to send them. Is my message being discarded by default? I do not get the answer in other threads.

Do you flush the outputstream on the PCs sending data?

// Send data here  
yourOutputStreamReference.flush();

There should be a loop in both ClientSocket and ServerSocket that keeps communication in the active state.

Otherwise: There should be implementation of both client socket and a server socket on all the sides (all the sender and receiver devices). When a server socket A receives a message, in order to reply back, there should be a client socket that replies back to server socket B which resides in the sender's application in his device.

In this way, all the devices with a server socket with the same port can detect and send messages to each other.

Of course the IP address of the sender should be kept in order to reply back.

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