简体   繁体   English

java套接字监听不接受连接?

[英]java socket listen without accepting the connection?

I'm new to Java, but not new to programming; 我是Java的新手,但不是编程的新手。 I've been around computers since the days of DOS. 从DOS时代开始,我就一直在计算机旁工作。

I'm trying to write a simple network proxy, and I want to listen for incoming connection requests, but I don't want to accept the request just yet as the client will then immediately send data. 我正在尝试编写一个简单的网络代理,并且我想监听传入的连接请求,但是我现在还不想接受该请求,因为客户端随后将立即发送数据。 I want the proxy to attempt to successfully open a connection to the pre-configured destination before accepting the connection, and drop the connection if the destination cannot be reached. 我希望代理尝试在接受连接之前尝试成功打开与预配置目标的连接,并在无法到达目标时断开连接。

This was possible in VB6 way back when, and I believe it's possible to do it in C# using events, but the problem is that the proxy machine is unix and I just don't feel masochistic enough to write anything in C++ just for one system. 当时,这在VB6中是可能的,而且我相信可以使用事件在C#中完成,但是问题是代理计算机是Unix,而我只是觉得受虐狂不足以只为一个系统编写C ++ 。

anyone got any ideas on how to do this, or at least a kludge to simulate such a thing? 任何人都对如何执行此操作有任何想法,或者至少有一个模仿这样的事情的想法? the article I saw here is too vague, and seems to be outdated as oracle docs seem to redirect to a different page. 我在这里看到的文章太含糊,并且似乎已经过时,因为oracle文档似乎重定向到另一个页面。

This isn't possible in Java. 这在Java中是不可能的。 The way the socket libraries are written you cannot get details about an incoming connection without accepting it. 套接字库的编写方式无法在不接受传入连接的情况下获得有关传入连接的详细信息。

The link you provided would only help in rejecting connections before accepting them but I don't think it would allow you to use a connection the SecurityManager rejected. 您提供的链接只会在接受连接之前帮助您拒绝连接,但我认为它不会允许您使用SecurityManager拒绝的连接。

Would it be possible to open the connection to the destination before accepting a connection, so then you only accept while you have a connection open to the destination? 在接受连接之前是否可以打开与目标的连接,所以只有在对目标开放的连接上才接受?

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

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