WiFi communication between 2 MKR1010 boards

I am in the process of making a scoreboard controlled by a handheld keypad. The plan is for the scorer to add to the scores using the keypad to generate 4 digits to be sent by WiFi to the scoreboard, where they drive 4 x digit display units. I have sorted out the program for the handheld keypad to generate the 4 seperate digits. I have also sorted out the programme to convert the 4 communicated digits to drive the displays. I'm struggling with setting the WiFi to send the 4 digits from one board to the other.

I am using 2 MKR1010WiFi boards to code and decode the 4 digits, but I can't work out how to use the WiFiNINA library to set up the sender and receiver stations to make the WiFi work. I feel this should be straightforward and simple, if only I know what I was doing.

I would be grateful for any clues to how this should be done done.

WiFiClient object wraps a TCP socket. A normal TCP socket is connected to IP address and port. WiFiServer starts a listening socket on a port. If server on listening socket is contacted by a remote client socket, it creates a local socket connected with the remote client socket on a free port and returns a WiFiClient object wrapping the socket. Everything you write or print to a WiFiClient is send to that one remote socket.

If one of your client boards creates a WiFiClient and connects it to IP address and port of the WiFiServer on your 'server' board, then you get there a WiFiClient from server.available() and this two WiFiClient objects are connected. What you write/print on one side you read only from the WiFiClient object on the other side.

client socket

    if (client.connect(serverIP, PORT)) {
      client.print("request\n");
      String response = client.readStringUntil('\n');
      Serial.println(response);
      client.stop();
    }

server side

    WiFiClient client = server.available();
    if (client && client.connected()) {
      String request = client.readStringUntil('\n');
      Serial.println(request);
      client.print("response\n");
      client.stop();
    }

Thank you for the explanation and the code in response to my query.

I’m sorry I haven’t replied earlier, but I have been trying to implement what you suggested. I think I understand the purpose of the 2 chunks of code you described and they would do exactly what I am looking for. But I assume these have to be inserted into a sketch for the server and for the client so that are able to communicate over the WiFi link. I’m having trouble working out how to do this.

I am struggling over getting my two boards to talk to each other. Most of the examples I find that describe making a Wi-Fi connection involve linking these to a web browser i.e. working through a computer to switch LEDs on and off.

I assumed I would be able to give my boards a name each — e.g. client and server — and then identify each for communication. But I haven’t yet managed to sort this. Most examples I see seem to refer to IP addresses. I assume I have to register IP addresses through DNS – is that the case? I have the MAC addresses, but I can't see how to use these with WiFiNINA.

So I appologise for not being clearer or being able to act on the advice you gave. Like many people on the Forum I’m new to this and I am starting to fear that one needs to be able to program in C++ to make decent progress with WiFi. I hope that’s not the case.

Thanks again. I’ll struggle on until I get to a stage when I can put your suggestions to good use.

see and try the WiFiChatServer example of the WiFiNINA library for complete example of a server.

the client connects to the IP address of the server

Thanks a lot. I'll focus on that.