Docker to Docker Networking Between TCP Client and Server
This article presents a step-by-step instructions on how to create a TCP client and server for IoT applications using Docker containers and networking.
Join the DZone community and get the full member experience.Join For Free
A TCP-based client and server are a frequently needed setup in IoT-based applications.
Presented in this article are:
- A method to create a Java-based client and server to send and receive binary data
- The client and server, each run inside a Docker container and communicating through Docker networking.
You may also enjoy: Understanding Docker Networking
Create a TCPClient.java as per the code provided below
Create a manifest file for the TCPClient as is shown below:
Create a Dockerfile for TCPClient as below:
Create a TCPServer.java as per the code provided below:
Create a manifest file for TCPServer as below:
Create a Dockerfile for TCPServer as below
The directory structure should be as displayed as shown below:
Run the following commands at the unix prompt:
Create the network:
Run the server:
Run the client:
You should see the client output as shown below:
And the server output should be as shown below:
Opinions expressed by DZone contributors are their own.