Skip to content

ForwardedPortLocal: "System.Net.Sockets.SocketException (48): Address already in use" for every port I try #1779

@ol1ver

Description

@ol1ver

I'm using a MacBook Air M2 with the latest macOS 26.4.
SSH.net in version 2025.1.0 (tested also the latest develop branch), .NET in version 10.
ssh executable works fine.


I'm trying to forward a local port to my server.

_listener = new Socket(ep.AddressFamily, SocketType.Stream, ProtocolType.Tcp) { NoDelay = true };
_listener.Bind(ep);
_listener.Listen(5);
if (!_listener.AcceptAsync(e))

Every port I try, $${\color{purple}Bind}$$ throws System.Net.Sockets.SocketException (48): Address already in use.
Even though $${\color{purple}Listen}$$ in the next line is never called nor $${\color{purple}AcceptAsync}$$, the tunnel works.
Even after the application is closed.

The left side is my MacBook, the right side the server.
Image


My test code:

using var sshClient = new SshClient("server", 22, "oliver", "password");
sshClient.Connect();
var local = new ForwardedPortLocal(12345, "127.0.0.1", 5000);
sshClient.AddForwardedPort(local);
try {
    local.Start();
} catch (Exception ex) {
    Console.WriteLine(ex);
}

Console.Write("Press ENTER to exit");
Console.ReadLine();

Does anyone have an explanation for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions