This is an example project that shows how to easily integrate java-ngrok
with a simple TCP Server and Client.
This is an example of a simple TCP ping/pong server. It opens a local socket, uses ngrok to tunnel to that socket,
then the client/server communicate via the publicly exposed address.
This project will reserve (and then release) its own TCP address using ngrok's API.
Build the application with:
make buildStart a socket server with:
USE_NGROK=true \
NGROK_AUTHTOKEN="my-auth-token" \
NGROK_API_KEY="my-api-key" \
java -jar build/libs/java-ngrok-example-tcp-server-and-client-1.0.0-SNAPSHOT.jar serverIt’s now waiting for incoming connections, so start a client in another terminal to send it something. Start a socket client with:
USE_NGROK=true \
HOST="1.tcp.ngrok.io" \
PORT=12345 \
java -jar build/libs/java-ngrok-example-tcp-server-and-client-1.0.0-SNAPSHOT.jar clientAnd that’s it! Data was sent and received from a socket via your ngrok tunnel.