Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: how do i use my listening ports on my mac?

  1. #1
    Junior Member
    Join Date
    Nov 2019
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how do i use my listening ports on my mac?

    okay I'm trying to use "ssh" local host 22 on my mac and for some reason it is saying this error ssh: connect to host localhost port 22: Connection refused
    this is my code:


    import java.io.IOException;
    import java.io.OutputStream;
    import java.net.ServerSocket;
    import java.net.Socket;

    public class ServerMain {
    public static void main(String[] args) {
    int port = 22;
    try {
    ServerSocket serverSocker = new ServerSocket(port);
    while (true) {
    Socket clientSocket = serverSocker.accept();
    OutputStream outputStream = clientSocket.getOutputStream();
    outputStream.write("Hello World\n".getBytes());
    clientSocket.close();
    }
    } catch (IOException e) {
    e.printStackTrace();
    }

    }
    }

  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: how do i use my listening ports on my mac?

    Can you copy the full text of the error message and paste it here?
    Is this a java problem or a mac OS problem?

    Please edit your post and wrap your code with code tags:

    [code]
    **YOUR CODE GOES HERE**
    [/code]

    to get highlighting and preserve formatting.
    If you don't understand my answer, don't ignore it, ask a question.

Similar Threads

  1. Web Browser listening
    By badoumba in forum What's Wrong With My Code?
    Replies: 1
    Last Post: November 28th, 2013, 09:25 AM
  2. JFrame Movement Listening
    By aussiemcgr in forum AWT / Java Swing
    Replies: 3
    Last Post: March 9th, 2011, 11:48 AM
  3. Listening to 2 Key Presses
    By aussiemcgr in forum Java Theory & Questions
    Replies: 3
    Last Post: January 18th, 2011, 06:09 PM
  4. Replies: 1
    Last Post: December 6th, 2010, 10:09 AM