I'm receiving socket errors in Java, it connects to the socket each time with a different proxy and it returns an error, I checked the proxies so they're not dead. I'm not sure what is causing this.
Here is the main functions.
public static Socket proxiedSocket(String[] con, String[] Prox)
{
int port = Integer.parseInt(Prox[1]);
int chatport = Integer.parseInt(con[1]);
InetSocketAddress SOCKS = new InetSocketAddress(Prox[0], port);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, SOCKS);
Socket socket = new Socket(proxy);
InetSocketAddress inet = new InetSocketAddress(con[0], chatport);
try
{
socket.connect(inet, 7000); // 5 Second Timeout
}
catch(SocketTimeoutException e)
{
log("Could not connect connect to socket! Reason: timed out!");
try
{
socket.close();
}
catch(Exception ee) { log("Could not close socket!"); }
}
catch(IOException e)
{
log(e.getMessage());
return socket;
}
return socket;
}
public static void send(Socket socket, String data)
{
try
{
DataOutputStream dOut = new DataOutputStream(socket.getOutputStream());
// Send first message
dOut.writeByte(1);
dOut.writeUTF(data);
dOut.flush(); // Send off the data
// Send the exit message
dOut.writeByte(EOF);
dOut.flush();
dOut.close();
}
catch (Exception e)
{
log("Error sending data to server: " + e.getMessage());
}
}
public static String read(Socket socket)
{
try
{
int b;
ByteArrayOutputStream ba = new ByteArrayOutputStream(200);
InputStream reader = socket.getInputStream();
String packet = "";
while((b = reader.read()) > 0)
{
ba.write(b);
}
if(b == -1)
{
ba.close();
return "False";
}
packet = ba.toString("UTF-8");
ba.flush();
ba.close();
return packet;
}
catch(Exception e)
{
log("Error while reading from server: " + e.getMessage());
return "False";
}
}
This is multi threading by the way.
so after each thread calls this: Socket socket = core.proxiedSocket(this.chatcon, this.proxy);
These are the errors I get.
Error while reading from server: Socket is closed
Malformed reply from SOCKS server
Connection refused: connect
Error sending data to server: Socket is not connected
Error while reading from server: Socket is not connected
Connection reset
connect timed out
Thanks in advance, if something is unclear please say so in the comments!