I am going to create a socket and get an InputStream
. Here is how I try it.
try {
final String serverIP = "111.111.111.111";
final int serverPort = Integer.parseInt(server_port);
final InetAddress serverAd=InetAddress.getByName(serverIP);
final InetAddress localAd =InetAddress.getByName(local_ip);
final int localPort = 4040;
Socket socket = new Socket(serverAd, serverPort, localAd, localPort);
}
But there is an exception thrown,
java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:276)
at shootist.Porter.run(Porter.java:41)
Here the server sends me rtp data and server side is ok and confirmed. I sent invite and got 200 as well. If there is a problem in my IP and port, I think, all responses cannot delivered to my IP and given Ports. But it can't happen as the server sends me responses to my IP and given port number. How I can fix this issue? Where I am wrong and what?