I'm trying to connect to a socket and then check if it is connected. My problem is that my socket IS connecting but when I ask if it is, it returns null.
How I'm getting my connection:
package main;
import java.io.IOException;
import java.net.Socket;
public class getIrcConnection {
String Server = "tmi.twitch.tv";
int Port = 80;
declars declars = new declars();
public getIrcConnection() throws IOException{
this.declars.socket = new Socket(Server, Port);
}
}
Where my socket is stored:
package main;
import java.net.Socket;
public class declars {
Socket socket;
}
How I'm checking the connection:
package main;
public class checkIrcConnection {
declars declars = new declars();
public checkIrcConnection() {
if (this.declars.socket.isConnected()) {
System.out.println("Connected");
}
}
}
All of this is beeing executed in the main method:
package main;
public class Main {
public static void main(String[] args) throws Exception {
getIrcConnection gic = new getIrcConnection();
checkIrcConnection cic = new checkIrcConnection();
}
}