0

我有一个连接到代理的套接字,然后连接到我指定的远程服务器。但是我想要从代理到删除服务器的多个连接。所以我想为同一个代理创建 4 个套接字,并从 4 个套接字连接到远程服务器。

当我这样做时它不起作用,它只连接到代理一次。

这是伪代码:

static Socket[] liveCon = new Socket[300];
// This is the class that assigns a proxy and connects
// it is a temporary thread that connects and ends.
sockClass sockets = new sockClass; 

class main {
    for (int i = 0; i < livecon.length; i++) {
        sockets[i].start(); // Thread ends after it is connected
    }
}

class sockClass{
   main.liveCon[index] = new Socket(proxy);
   main.liveCon[index].connect(ep);
   main.liveCon[index].setPerformancePreferences(1, 2, 0);
   if (main.liveCon[index].isConnected() == true) {
       myOutput = new PrintStream(main.liveCon[index].getOutputStream());
       main.liveCon[index].setKeepAlive(true);
   }
}
4

2 回答 2

0

听起来您没有使用线程,而是尝试按顺序连接到代理。

由于您不发布问题示例,因此很难解决问题。

尝试运行您的程序 4 次,以查看问题出在您的代码中还是在代理中。

我希望这有帮助。

于 2010-09-23T04:46:05.507 回答
0

如果您不使用线程,除非您使用非阻塞 I/O,否则您无法正确执行此操作。

于 2010-09-23T13:32:54.370 回答