On a macOS system, listen on a local port via netcat in a loop:
while true; do nc -vlp 1337; sleep 1; done
# alternatively, to just listen once (nc exits after a single connection)
nc -vlp 1337Then from this directory, connect:
swift run rdncat localhost 1337 # use random source port, connect to localhost:1337
# or to specify source port
swift run rdncat localhost 1337 2345 # set source port to 2345, connect to localhost:1337In the nc (netcat) window, you should see the connection like so, where 5678 is the random source port:
Connection from 127.0.0.1:5678
And in the rdncat window, you'll see the source port outputted as well:
Connected from Optional(127.0.0.1:5678)
A Client-Server command-line tool that provides an echo server for TCP connections and a client to connect to any server accepting TCP connections.
The tool was created using Apple's NWFramework.
You can read the article explaining the command-line tool, here:
https://rderik.com/blog/building-a-server-client-aplication-using-apple-s-network-framework/
You can also get the "macOS network programming in Swift" guide. It includes more topics on building network applications on macOS, including:
- BSD Sockets in Swift
- Apple's Network.framework
- SwiftNIO
You can get it from the following link: