I have very simple loop to read serial port and write to client

// telnet defaults to port 23
Server server(23);

void setup() {
    Serial.begin(9600);// opens serial port, sets data rate to 9600 bps

    // initialize the ethernet device
    Ethernet.begin(mac, ip, gateway, subnet);

    // start listening for clients

void loop() {
    if (Serial.available() > 0) {
        char byte = Serial.read();

problem happens if serial port is open (on computer side) after ethernet connection is established, no data is transmitted

What gives? thank you

  • \$\begingroup\$ Can you give a bit more information about what Arduino shields you're using and what you're trying to achieve? \$\endgroup\$ Commented Aug 15, 2010 at 12:41
  • \$\begingroup\$ How do conditions differ when it works, and what does it do? \$\endgroup\$ Commented Aug 15, 2010 at 16:16
  • \$\begingroup\$ @Joby @Clint sorry for delay. ethernet is Wiznet module. condition where it fails is such: connection is established (serial port is closed on PC), serial port is opened on PC and written to. however, telnet connection does not receive written bytes. other combinations, first serial connection, then telnet connection work \$\endgroup\$
    – aaa
    Commented Aug 17, 2010 at 21:16

2 Answers 2


Maybe this is simplistic, but if you open the serial port on the computer, doesn't that make Serial.available() == 0?

You could light the LED on the board if that's true. Hope this helps.


I haven't really used processing but I have used C and I don't understand how you're getting away with having thatchar byte = Serial.read(); in the middle of the function. All variables should be defined at the start of the function and then used.

  • 3
    \$\begingroup\$ The Arduino language is C++ with automated headers and footers. In C++ (and C99) declaring variables mid code block is valid. \$\endgroup\$ Commented Aug 16, 2010 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.