Note that there are some explanatory texts on larger screens.

plurals
  1. POJava - Socket Programming / Blocked ports
    primarykey
    data
    text
    <p>I'm trying to do a simple example of a client that connects to any website using 8080 port and print the first input from server. But I can't even connect to the server. Trcking the TCP's headers with Wireshark, I realized that the servers aren't answering. I've already turn off my Firewall, Antivirus and set the forwardings ports in my router, but I still can't connect to the server. </p> <p>Here is my code:</p> <pre><code>import java.io.IOException; import java.io.InputStream; import java.net.InetSocketAddress; import java.net.Socket; import java.net.UnknownHostException; public class ProtocoloX { //private byte[] bytes = new byte[1024]; private byte[] bytes = new byte[]{(byte) 0xC6, 0x57, 0x54, (byte) 0x95, 0x5E, (byte) 0x9E, 0x6B, (byte) 0xC6, 0x55, 0x17, 0x55,0x52, (byte) 0x9E, 0x21}; private Socket cliente; private final String HOST = "stackoverflow.com"; private final int PORT = 8080; public boolean connect(){ this.cliente = new Socket(); System.out.println("-- Trying to connect: "+HOST+":"+PORT); InetSocketAddress socketAddress = new InetSocketAddress(HOST, PORT); try { this.cliente.connect(socketAddress, 10000000); } catch (IOException e) { System.out.println(e); System.out.println("-- CONNECTION PROBLEM "); return false; } System.out.println("-- Connection successful"); return true; } private void receive(){ InputStream stream = null; System.out.println("-- Reading data..."); try { stream = this.cliente.getInputStream(); try { int count = stream.read(this.bytes); System.out.println("count:"+count); System.out.println("bytes:"+this.bytes); } catch (IOException e) { System.out.println("-- DATA READING PROBLEM"); e.printStackTrace(); } } catch (IOException e) { System.out.println("-- DATA READING PROBLEM"); e.printStackTrace(); } System.out.println("-- Data read successful"); } public static void main(String[] args) throws UnknownHostException, IOException { ProtocoloX protocolo = new ProtocoloX(); if(protocolo.connect()){ protocolo.receive(); } } } </code></pre> <p>What could be causing the problem? Thanks :D</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload