1

i use the "client.availbale" to check incoming data on the (mkr1010) client coming from (mkr1010) server but it always contains "0". Serial printing (monitor) it on server works. It looks as if the data never arrives? Thanks for helping out !

client code :

if (client.connect(ServerIP, 23)) {
client.print("741G");
byte i = 0;
Serial.println(client.available());  


    while (client.available() > 0 && i < bufferSize) {

      incomingMessage[i] = client.read();
      Serial.println(incomingMessage[i]);
      Serial.println(i);
      // check if end of incoming message
      if (incomingMessage[i] == '\r') {
        // replace carriage return with null terminator
        incomingMessage[i] = '\0';
        // set array index counter to end
        i = bufferSize;
        // flush out any remaining control characters which would
        // stay in client buffer until next loop
        client.flush();
      }
      // increase array index counter
      i++;

my server code :

// when the client sends the first byte, say hello:
  if (client) {
    if (!alreadyConnected) {
      // clead out the input buffer:
      client.flush();
      Serial.println("We have a new client");
      client.println("Hello, client!");
      alreadyConnected = true;
    }

    if (client.available() > 0) {
      // read the bytes incoming from the client:
      char request = client.read();
      Serial.print(request);

      for (i = 0; i < 4; i = i + 1) {
      Serial.print(myseq[i]);
      server.write(myseq[i]);

      }
5
  • use client.write(). does the server print "We have a new client"? – Juraj Apr 11 '20 at 11:34
  • thanks for your reply. Apparently client.write gives same result. this is logic since if I'm right client.write writes to the specific client and server.write writes to all clients connected. – Majid Apr 11 '20 at 11:39
  • I don't know that specific board, but most often you need to accept the client's connection on the server with client = server.available(). – Majenko Apr 11 '20 at 12:50
  • that is done in another part of my server code. data from client to server works fine it is the other direction that doesn't work – Majid Apr 11 '20 at 14:18
  • @Majid that's what Majenko says. Do you use client.connected() anywhere? – Sim Son Apr 11 '20 at 16:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.