Skip to content
This repository has been archived by the owner on Oct 3, 2023. It is now read-only.

Commit

Permalink
Merge pull request #12 from rassware/main
Browse files Browse the repository at this point in the history
fix to use random ports
  • Loading branch information
ricaun authored Jul 3, 2021
2 parents fa622cf + 2535e07 commit 0a67e40
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions DuinoCoin_Esp_Master/DuinoCoin_Clients.ino
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ bool clients_connected(byte i)

bool clients_connect(byte i)
{
static int port = 0;
int port_size = sizeof(ports) / sizeof(ports[0]);
if (port >= port_size) port = 0;
int port_number = random(0, port_size - 1);

if (clients[i].connected())
{
Expand All @@ -51,9 +50,9 @@ bool clients_connect(byte i)
wire_readLine(i);

Serial.print("[" + String(i) + "]");
Serial.println("Connecting to Duino-Coin server...");
Serial.println("Connecting to Duino-Coin server... with port " + String(ports[port_number]));

if (!clients[i].connect(host, port))
if (!clients[i].connect(host, ports[port_number]))
{
Serial.print("[" + String(i) + "]");
Serial.println("Connection failed.");
Expand Down

0 comments on commit 0a67e40

Please sign in to comment.