在 ServerSocket 中有 setReuseAddress() 这个函数,是实现这个功能需要的吗??public void setReuseAddress(boolean on) throws SocketExceptionEnable/disable the SO_REUSEADDR socket option. When a TCP connection is closed the connection may remain in a timeout state for a period of time after the connection is closed (typically known as the TIME_WAIT state or 2MSL wait state). For applications using a well known socket address or port it may not be possible to bind a socket to the required SocketAddress if there is a connection in the timeout state involving the socket address or port. Enabling SO_REUSEADDR prior to binding the socket using bind(SocketAddress) allows the socket to be bound even though a previous connection is in a timeout state. When a ServerSocket is created the initial setting of SO_REUSEADDR is not defined. Applications can use getReuseAddress() to determine the initial setting of SO_REUSEADDR. The behaviour when SO_REUSEADDR is enabled or disabled after a socket is bound (See isBound()) is not defined.
WEB 服务器先已经在 80 号端口监听.
HTTPTunnel 启动后,也可以在 80 号端口监听,而且 WEB 也可以正常运行??这是怎么实现的啊??
这有啥问题呢?
要保证的是,HTTPTunnel能收全数据。
只要你程序不独占端口,是可以实现多个程序监听的。
但如何保证他们都能读全数据?
在 ServerSocket 中有 setReuseAddress() 这个函数,是实现这个功能需要的吗??public void setReuseAddress(boolean on)
throws SocketExceptionEnable/disable the SO_REUSEADDR socket option.
When a TCP connection is closed the connection may remain in a timeout state for a period of time after the connection is closed (typically known as the TIME_WAIT state or 2MSL wait state). For applications using a well known socket address or port it may not be possible to bind a socket to the required SocketAddress if there is a connection in the timeout state involving the socket address or port. Enabling SO_REUSEADDR prior to binding the socket using bind(SocketAddress) allows the socket to be bound even though a previous connection is in a timeout state. When a ServerSocket is created the initial setting of SO_REUSEADDR is not defined. Applications can use getReuseAddress() to determine the initial setting of SO_REUSEADDR. The behaviour when SO_REUSEADDR is enabled or disabled after a socket is bound (See isBound()) is not defined.
还是给最后一个绑定的程序?
还是象 ber() 所的:谁的指定最明确则将包递交给谁?这里的指明最明确,又是指的什么?谢谢大家了!
有学到了不少啊!!再请教大侠们一个问题:
哪位大侠写过HTTP服务器的模拟程序??
怎么判断客户机传送过来的数据已经完毕啊??
谢谢!! 用一个 while 循环读取, 如果没有数据 程序就会在 read() 函数处停止运行,必须要在 循环内部 判断已经读取完毕,及时跳出死循环 .比如做一个最简单的服务器, 把 IE 发过来的所有信息回发给 IE ,我首先要接收了所有的信息,才能发送啊? 我怎么判断接收的信息的完整性啊,又什么时候停止接收啊?
不是操作系统发的,socket不管有多少端口,只负责将数据送到指定端口
2、是给每个程序都一样的信息?还是给最后一个绑定的程序?
需要测试。
3、哪位大侠写过HTTP服务器的模拟程序??
看一下http协议吧
4、 用一个 while 循环读取
当read()返回-1时候,表示没有收到数据。
你可以定义自己的数据收发协议,里面包括此次发送数据多少。