开发者

Socket/Proxy problem in java

开发者 https://www.devze.com 2023-01-17 01:37 出处:网络
I have a socket connecting to a proxy then to a remote server i specify. However i want multiple connections to the remove server from the proxy. So i want to create 4 sockets to the same proxy and fr

I have a socket connecting to a proxy then to a remote server i specify. However i want multiple connections to the remove server from the proxy. So i want to create 4 sockets to the same proxy and from the 4 so开发者_StackOverflowckets connect to the remote server.

When i do this it doesn't work, it only connects to the proxy once.

Here is psuedo code:

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);
   }
}


Sounds like you're not using threads, but instead you try to connect to the proxy sequentially.

Since you don't post a sample of the problem is hard to trouble shot.

Try running your program 4 times instead to see if the problem is in your code or in the proxy it self.

I hope this helps.


If you're not using threading you cannot do this correctly unless you go to non-blocking I/O.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号