Before starting, check the IP of your machine within your network:
$ ifconfig Navigate to the TCPClient.Dockerfile file and change the HOST_TCP_SERVER address to your IP, line 7.
Do the same for the UDPClient.Dockerfile file and change the HOST_UDP_SERVER address to your IP, line 7.
Here it will be explained how to run the TCP server and client.
To start the container that will be responsible for running the server, run the following commands:
sd@sd:~ $ cd tcp/
sd@sd:~ $ docker build -t tcp-server -f TCPServer.Dockerfile .
sd@sd:~ $ docker run -d -p 12345:12345 tcp-server:latest-d option will cause the container to run in detached mode.-p 12345:12345: makes docker expose port 12345 of the container to your computer, so the service will be visible through other network interfaces within your machine. To start the container that will be responsible for executing the client role, execute the following commands:
sd@sd:~ $ cd tcp/
sd@sd:~ $ docker build -t tcp-client -f TCPClient.Dockerfile .
sd@sd:~ $ docker run tcp-client:latestclient will only connect to our previously run server, it won't expose any resources. And because it doesn't expose any resources, there is no port being exposed by this container.When run, this container should produce output similar to the following:
Time: 0.735 m/s
Time: 0.208 m/s
Time: 0.278 m/s
Time: 0.210 m/s
Time: 0.311 m/s
Time: 0.221 m/s
Time: 0.271 m/s
Time: 0.225 m/s
Time: 0.106 m/s
Time: 0.173 m/s
Tempo médio: 0.274 m/s
Desvio padrão: 0.172
Tempo máximo: 0.735 m/s
Tempo mínimo: 0.106 m/s Here it will be explained how to run the UDP server and client.
To start the container that will be responsible for running the server, run the following commands:
sd@sd:~ $ cd udp/
sd@sd:~ $ docker build -t udp-server -f UDPServer.Dockerfile .
sd@sd:~ $ docker run -d -p 54321:54321/udp udp-server:latest-d option will cause the container to run in detached mode.-p 54321:54321/udp option makes docker expose the container's port 54321 to your computer, so the service will be visible through other network interfaces within your machine.-p 54321:54321/udp , we use /udp , this is necessary because, by default, docker maintains a TCP communication and in this case we need it to be a UDP communication. To start the container that will be responsible for executing the client role, execute the following commands:
sd@sd:~ $ cd udp/
sd@sd:~ $ docker build -t udp-client -f UDPClient.Dockerfile .
sd@sd:~ $ docker run udp-client:latestclient will only connect to our previously run server, it won't expose any resources. And because it doesn't expose any resources, there is no port being exposed by this container.When run, this container should produce output similar to the following:
From server: Hi, Client. Ok!
Time: 0.174 m/s
From server: Hi, Client. Ok!
Time: 0.116 m/s
From server: Hi, Client. Ok!
Time: 0.086 m/s
From server: Hi, Client. Ok!
Time: 0.080 m/s
From server: Hi, Client. Ok!
Time: 0.074 m/s
From server: Hi, Client. Ok!
Time: 0.091 m/s
From server: Hi, Client. Ok!
Time: 0.065 m/s
From server: Hi, Client. Ok!
Time: 0.098 m/s
From server: Hi, Client. Ok!
Time: 0.081 m/s
From server: Hi, Client. Ok!
Time: 0.107 m/s
Tempo médio: 0.097 m/s
Desvio padrão: 0.031
Tempo máximo: 0.174 m/s
Tempo mínimo: 0.065 m/s