简体   繁体   English

通过Java中的特定套接字将httpServer连接到客户端

[英]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(). 我做了一个httpServer,它通过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? 请参阅如何确定HTTP的源端口? Is there ever collision in NAT? NAT中是否有冲突?

Why do you want to do that? 你为什么要这么做?

An httpServer only responds on client requests. httpServer仅响应客户端请求。 It cannot send data to the client without a request from the client. 没有客户端的请求,它无法将数据发送到客户端。 If you want to have bi-directional communication, you need websockets. 如果要进行双向通信,则需要websocket。

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

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