Class MCPLoopbackSocketTransport
java.lang.Object
com.codename1.mcp.MCPLoopbackSocketTransport
- All Implemented Interfaces:
MCPTransport
Loopback socket MCP transport built on the portable Socket API, so
an agent can attach to a running app on ANY port that can bind the loopback interface -
a device or simulator, not only the desktop.
The channel is bound to loopback only. That is the security boundary: an attaching agent can read the screen and drive the UI, so it must already be on the device (or on a host forwarding into it), never merely on the same network. There is no wildcard fallback; if the port cannot bind loopback this transport refuses to open.
The listening socket stays bound across client sessions, so an agent may disconnect and reconnect - each drive call is typically its own short-lived connection - without the server thread exiting.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classThe per-connection callback the socket API instantiates. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the transport and releases any underlying resources.intgetPort()voidopen()Opens the transport, blocking until it is ready to exchange messages.Reads the next complete JSON-RPC message.voidwriteMessage(String message) Writes a complete JSON-RPC message and flushes it.
-
Method Details
-
getPort
public int getPort() -
open
Description copied from interface:MCPTransportOpens the transport, blocking until it is ready to exchange messages. For a socket transport this waits for the first client connection.- Specified by:
openin interfaceMCPTransport- Throws:
IOException
-
readMessage
Description copied from interface:MCPTransportReads the next complete JSON-RPC message. Returns null at end of stream.- Specified by:
readMessagein interfaceMCPTransport- Throws:
IOException
-
writeMessage
Description copied from interface:MCPTransportWrites a complete JSON-RPC message and flushes it. The value must not contain embedded newlines.- Specified by:
writeMessagein interfaceMCPTransport- Throws:
IOException
-
close
public void close()Description copied from interface:MCPTransportCloses the transport and releases any underlying resources.- Specified by:
closein interfaceMCPTransport
-