Port forwarding lets your local machine communicate directly with services running inside a Sprite over a transparent TCP tunnel. The SDK establishes a local listener and proxies each connection through a WebSocket transport to the Sprite, so you can use any standard networking tool againstDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/superfly/sprites-go/llms.txt
Use this file to discover all available pages before exploring further.
localhost while the actual service runs remotely.
Forward a single port
ProxyPort creates one forwarding session. Pass the context, the local port to bind, and the remote port on the Sprite.
*ProxySession keeps the listener alive until you call Close() or the parent context is cancelled.
Forward multiple ports
ProxyPorts accepts a slice of PortMapping values and returns a slice of sessions in the same order. If any mapping fails, all sessions created so far are cleaned up before the error is returned.
PortMapping struct
PortMapping describes one local-to-remote binding:
RemoteHost when the target service listens on a specific IP address or hostname inside the Sprite’s network, for example "10.0.0.1" or "fdf::1".
Managing a ProxySession
A*ProxySession exposes three methods for lifecycle control:
| Method | Description |
|---|---|
Close() error | Stops accepting new connections and closes the local listener |
Wait() | Blocks until the session is closed |
LocalAddr() net.Addr | Returns the bound local address |
Auto-forwarding with port notifications
When you run a command inside a Sprite, you can set aTextMessageHandler on the Cmd to receive PortNotificationMessage events whenever a process opens or closes a port. Use this to automatically start and stop forwarding sessions.
PortNotificationMessage fields
Use
notification.Address as the RemoteHost in your PortMapping. This ensures the proxy connects to the exact address the process is listening on, which matters when a service binds to a non-loopback interface.Open a raw connection
ProxySocket returns a net.Conn instead of a listener. Use this when you need a single direct connection to an arbitrary address inside the Sprite rather than a persistent forwarding session.
Managing multiple sessions with ProxyManager
ProxyManager collects sessions so you can close or wait on all of them together without tracking the slice yourself.
| Method | Description |
|---|---|
NewProxyManager() | Creates an empty manager |
AddSession(session) | Registers a session with the manager |
CloseAll() | Closes every registered session |
WaitAll() | Blocks until every registered session has closed |
Transport details
All proxy connections use the WebSocket protocol. When the Sprite supports thecontrol feature, the SDK reuses a pool of persistent WebSocket connections to reduce connection setup overhead. Older Sprites fall back to opening a new WebSocket per TCP connection.
Because connections are tunneled over WebSocket, raw TCP keepalive settings on your local socket do not propagate to the remote side.