Go Down

Topic: Yun TCP IP (Read 390 times) previous topic - next topic

thedoctor46

Hello everyone, I need some help for my project. I am trying to connect my Arduino Yun with my PC via TCP connection. I have developed a simple C# app that sends and receives data over TCP, tested it and it works. Now, I am trying to write a code for my Yun, to communicate with my PC. Here is my code:

Code: [Select]

#include <Bridge.h>
#include <BridgeServer.h>
#include <BridgeClient.h>

BridgeServer server(23);

boolean alreadyConnected = false;


void setup() {

Serial.begin(9600);



  Bridge.begin();
  server.begin();
 
}

void loop() {

  BridgeClient client = server.accept(); 

  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 thisChar = client.read();
      // echo the bytes back to the client:
      client.write(thisChar);
      // echo the bytes to the server as well:
      Serial.write(thisChar);
    }
  }
  } 
}   


As you can see, it is a very simple code, almost the same as the Ethernet Chat Server example. I have tried to communicate with my PC and it doesn't worked. First I thought that my C# app doesn't works, but it works fine.

After that, I downloaded the SocketTest v3 software, and tried to communicate with my Yun. When I connects to the Yun, it sends me back the message: "Hello client" and it writes to the serial monitor: "We have a new client" but it doesn't responds to any other message.

Any suggestion? What am I doing wrong?

Go Up