Can not chat in two directions using Arduino Ethernet Shield, why?

I have my own project to make my Notebook and Netbook could chat each other using Arduino Ethernet Shield.

I pile up my Arduino UNO and Arduino Ethernet Shield,
then I connect my Notebook to Arduino UNO using USB printer cable then I connect my Netbook to Arduino Ethernet Shield using RJ 45 cable.

Then I upload ChatServer sketch from my Notebook to Arduino UNO with this change:

...
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xFE, 0xAC }; //same with the sticker
IPAddress ip(192,168,1, 77); // ip address assigned to my Arduino Ethernet shield
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 0, 0);
...

So my full sketch is:

/*
 Chat  Server
 
 A simple server that distributes any incoming messages to all
 connected clients.  To use telnet to  your device's IP address and type.
 You can see the client's input in the serial monitor as well.
 Using an Arduino Wiznet Ethernet shield. 
 
 Circuit:
 * Ethernet shield attached to pins 10, 11, 12, 13
 * Analog inputs attached to pins A0 through A5 (optional)
 
 created 18 Dec 2009
 by David A. Mellis
 modified 10 August 2010
 by Tom Igoe
 
 */

#include <SPI.h>
#include <Ethernet.h>

// Enter a MAC address and IP address for your controller below.
// The IP address will be dependent on your local network.
// gateway and subnet are optional:
byte mac[] = { 0x90, 0xA2, 0xDA, 0x00, 0xFE, 0xAC };
IPAddress ip(192,168,1, 77);
IPAddress gateway(192,168,1, 1);
IPAddress subnet(255, 255, 0, 0);

// telnet defaults to port 23
EthernetServer server(23);
boolean gotAMessage = false; // whether or not you got a message from the client yet

void setup() {
  // initialize the ethernet device
  Ethernet.begin(mac, ip, gateway, subnet);
  // start listening for clients
  server.begin();
  // open the serial port
  Serial.begin(9600);
}

void loop() {
  // wait for a new client:
  EthernetClient client = server.available();
  
  // when the client sends the first byte, say hello:
  if (client) {
    if (!gotAMessage) {
      Serial.println("We have a new client");
      client.println("Hello, client!"); 
      gotAMessage = true;
    }
    
    // read the bytes incoming from the client:
    char thisChar = client.read();
    // echo the bytes back to the client:
    server.write(thisChar);
    // echo the bytes to the server as well:
    Serial.print(thisChar);
  }
  
}

Then, in my netbook I open RUN (Windows XP) then type TELNET then type o 192.168.1.77 [23]
Then it responds well, so everything I type in my netbook, it will appear int my notebook using Serial Monitor for Arduino

But I can not send any character from my notebook to the netbook, anyone know why ?
Any solution so they can communicate in two direction?
Is my notebook server/client?
is my netbook server/client?
I confuse...

Vielen Dank...

The sketch you are running communicates via ethernet. Only one of your machines is connected to the ethernet port on the shield, so only one of your machines can telnet to the Arduino.

If I use router to connect to my Arduino then from the router to many machine (PC,Notebook,Netbook),
then can I communicate in two direction, I mean not only receive chat but also send a chat?

dxw00d:
The sketch you are running communicates via ethernet. Only one of your machines is connected to the ethernet port on the shield, so only one of your machines can telnet to the Arduino.

Hmm maybe it is because we use telnet (telecommunication network) so it can only communicate using ethernet cable, is there any other way (maybe not using telnet) so there are more than one machine can communicate to the Arduino?

anyone can respond! :drooling_face:

creativen:
I have my own project to make my Notebook and Netbook could chat each other using Arduino Ethernet Shield.

Why use the Arduino for this? What does it achieve?

I pile up my Arduino UNO and Arduino Ethernet Shield, then I connect my Notebook to Arduino UNO using USB printer cable

The printer cable?

Actually at first, I want to do a trial so I know how the Ethernet Shield work.
Then It is just fun I can use arduino for communication between PCs

For my project, I want to control my arduino using LAN cable, in my case I want to control the arduino from my netbook, any idea for this?

I pile up my Arduino UNO and Arduino Ethernet Shield, then I connect my Notebook to Arduino UNO using USB printer cable

The printer cable?

Yes, the usb printer cable like in this image

That's a USB Type A (the flat end) to Type B (the squarish end) cable. It is often used for printers, but that doesn't make it a printer cable. External hard disks often use that type of cable, as do scanners, and many other things.

creativen:
If I use router to connect to my Arduino then from the router to many machine (PC,Notebook,Netbook),
then can I communicate in two direction, I mean not only receive chat but also send a chat?

dxw00d:
The sketch you are running communicates via ethernet. Only one of your machines is connected to the ethernet port on the shield, so only one of your machines can telnet to the Arduino.

Hmm maybe it is because we use telnet (telecommunication network) so it can only communicate using ethernet cable, is there any other way (maybe not using telnet) so there are more than one machine can communicate to the Arduino?

Anyone could help me to answer this?

Well first off you have to understand that the Ethernet shield is very limited that chip only supports 4 simultaneous sockets (telnet connections). That chip has 8x the ram of a 328 and does most of the heavy lifting. You seem to be looking to implement this http://arduino.cc/en/Tutorial/ChatServer

His notebook is connected via USB to the Arduino.
His netbook is connected via telnet to the Arduino.

If I understand correctly, his question is why he can send a telnet message from his netbook to the Arduino and see it in the serial monitor on his notebook, but if he types a message into the serial monitor on his notebook why he cannot see it in his telnet session on his netbook.

The answer is simple: because the sketch is not designed to do that. The sketch never performs any Serial.read() and never does anything with the data you're typing into the serial monitor -- it's a debugging, read-only display.

If from your notebook you opened a telnet session to the server and typed your commands there then the sketch should behave in the way you're expecting.

Chagrin:
His notebook is connected via USB to the Arduino.
His netbook is connected via telnet to the Arduino.

If I understand correctly, his question is why he can send a telnet message from his netbook to the Arduino and see it in the serial monitor on his notebook, but if he types a message into the serial monitor on his notebook why he cannot see it in his telnet session on his netbook.

You are right exactly! You clear all misunderstanding, I might have problem in my english.

Chagrin:
The answer is simple: because the sketch is not designed to do that. The sketch never performs any Serial.read() and never does anything with the data you're typing into the serial monitor -- it's a debugging, read-only display.

is there a sketch to fulfill my needs? two way chat?

Chagrin:
If from your notebook you opened a telnet session to the server and typed your commands there then the sketch should behave in the way you're expecting.

How I open a telnet session to the server from my notebook if I just connect it using USB cable not RJ 45 cable?

Vielen Dank.

How I open a telnet session to the server from my notebook if I just connect it using USB cable not RJ 45 cable?

You can't.

If I use router to connect to my Arduino then from the router to many machine (PC,Notebook,Netbook),
then can I communicate in two direction, I mean not only receive chat but also send a chat?

Did you try this?

dxw00d:

If I use router to connect to my Arduino then from the router to many machine (PC,Notebook,Netbook),
then can I communicate in two direction, I mean not only receive chat but also send a chat?

Did you try this?

No I did not, I want to make sure if it is possible then I will buy the router, just for fun to use arduino to chat...
Logically it should work, shouldnt it?

Do you not already have a router, for broadband?

dxw00d:
Do you not already have a router, for broadband?

I dont have a router yet...
What do you mean to tell me?

I don't mean to tell you anything. I was just asking if you already had a broadband router.

So many misconceptions and misunderstandings that even I got lost in the way.

I'll try to get this straight, to everyone, including myself:

So he's got 2 PCs. Call them PC1 and PC2. The PC1 is connected to the Arduino using the USB cable, so that means he is controlling the arduino with PC1?

And the Arduino (and the Ethernet shield) and PC2 are connected via Ethernet cable. So he's sending a message from PC1 to PC2 via the Arduino, and wondering why he cannot reverse that, am I right?

If this is the case, the Arduino serves as a vessel for the message from PC1 to PC2, respectively "Sender" and "Receiver". The Arduino between Sender and Receiver acts as Forwarder, it forwards to message to the Receiver, via the Ethernet cable.

Now, metaphorically this is like a superball that doesn't bounce back, because you're throwing it in a bucket of cement.

For each connection, you need something that delivers it. In this case, you want a connection like this:

  • PC1 to Arduino -> Arduino to PC2

Simplifying this you need 3 different connections (Though in reality you need more). Now you only have 2, so you need a connection from PC2 back to PC1. It's just like upload and download connections, you need both while browsing the internet.

If I am right, you can achieve this by connecting the Arduino to your broadband router/modem, or the same network your PC1 and PC2 are on.
However, I doubt the same sketch would work in that case.

So he's got 2 PCs. Call them PC1 and PC2. The PC1 is connected to the Arduino using the USB cable, so that means he is controlling the arduino with PC1?

And the Arduino (and the Ethernet shield) and PC2 are connected via Ethernet cable. So he's sending a message from PC1 to PC2 via the Arduino, and wondering why he cannot reverse that, am I right?

I just upload code using PC1...
I'm sending message from PC2 to PC1 via Arduino, it works, but I wonder why I cannot reverse it (sending message from PC1 to PC2)
The rest is right... :wink:

Take a look at the code in this thread:

It is a simple telnet type connection that works both ways. It is by no means complete, just a test. But it should give you an idea how it works. Feel free to modify it to your heart's content.

edit: That code above is a bit lacking. Try this. It is a bit better for two way comm. Change the network settings to yours. It will timeout the connected client if there is no input for about a minute.

#include <SPI.h>
#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip( 192,168,2,2 );
IPAddress gateway( 192,168,2,1 );
IPAddress subnet( 255,255,255,0 );

EthernetServer server(23);

int loopCount = 0;
boolean isStopped;

void setup()
{
  Serial.begin(9600);
  pinMode(4,OUTPUT);
  digitalWrite(4,HIGH);
  Ethernet.begin(mac, ip, gateway, gateway, subnet);
  delay(2000);
  server.begin();
  Serial.println("Ready");
}

void loop()
{
  EthernetClient client = server.available();

  if(client)
  {
    Serial.println("Client connected");
    client.flush();
    isStopped = false;
    loopCount = 0;
    char c;
    
    client.println("Hello");

    while(Serial.available()) Serial.read();
    
    while (client.connected()) 
    {
      while(client.available()) 
      {
        c = client.read();

        if(c == 'x')
        {
          client.stop();
          Serial.println("stop - user request");
          isStopped = true;
        }
        else Serial.write(c);

        loopCount = 0;
      }

      delay(10);
      
      loopCount++;

      if(loopCount > 10000)
      {
        client.stop();      
        Serial.println("stop - timeout");
        isStopped = true;
      }

      while(Serial.available())
       {
          c =Serial.read();
          client.write(c);
          Serial.write(c);
       }
    }

    if(!isStopped)
    {
      client.stop();
      Serial.println("stop - disconnect");
    }    

    Serial.println("disconnected");
  }
}

creativen:
I just upload code using PC1...
I'm sending message from PC2 to PC1 via Arduino, it works, but I wonder why I cannot reverse it (sending message from PC1 to PC2)
The rest is right... :wink:

Like I said, you don't have the necessary connections. Right now, you have a connection from PC2 to PC1, but not the other way around.