简体   繁体   中英

Connect httpServer to client through a specific socket in java

I have made an httpServer which is connected with the client with Socket client = socket.accept(). Is there a command in order to choose which port I want to use to send messages to the client??

服务器将使用创建ServerSocket socket = ServerSocket(your port)

You want to have a fixed outbound port on the client? You can't do that.

See How is source port for HTTP determined? Is there ever collision in NAT?

Why do you want to do that?

An httpServer only responds on client requests. It cannot send data to the client without a request from the client. If you want to have bi-directional communication, you need websockets.

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