Java Socket Chat unable to establish connection to port


I am trying to code a simple server and client chat application, however my code jumps straight to the exception, meaning it cannot create the connection to the port.


public class Server
   public static void main(String args[])
       ServerSocket ss = new ServerSocket(80);
       Socket sock = ss.accept();
       DataInputStream recive = new DataInputStream(sock.getInputStream());
       DataOutputStream sendOut = new DataOutputStream(sock.getOutputStream());
       BufferedReader readOut = new BufferedReader(new InputStreamReader(;

       String in = "";
       String out = "";
       Scanner scan = new Scanner(;
       System.out.println("Talk with client(y/n): ");
       String start = scan.nextLine();
       while(start == "y")
       in = recive.readUTF();
       out = readOut.readLine();
    catch(IOException e)
    {System.out.println("[!]CANNOT ESTABLISH CONNECTION[!]");}



Make sure that the port that you have specified is not already in use (port number 80) . It is likely that you may be running another application on the same port (such as a web server).

You can also refer this example: Basic Client and Server Communication using a Socket

By : Hiren

The reason this is not working as you expect is you are comparing JSON text to a text value.

You should cast the JSON value to the appropriate type, which is numeric, and compare to a number.

For example:

    select address from listing where ('address.coords.latitude')::numeric < 40;
By : slayer49

You're calling your static variable/method through object instead of the class where it's defined. When it says 'by declaring type ' it means that you declared your variable/method as a class variable/method and you should call it by that.

This video can help you solving your question :)
By: admin