HELP:Convert Serial to TCP&send frm Arduino to PC

Hi,

Does someone here knows how to convert Serial to TCP packet?
I’m having a problem to convert Serial data into TCP packet & send it from Arduino to my PC. I managed to convert UDP to Serial and Serial back to UDP packet, also able to convert TCP to Serial, but have no luck converting Serial to TCP packet.

If anyone knows about this matter, appreciated if could lend me some help. I’m using Duemilanove and Ethernet Shield.

I posted my source code for easier reference.

#include <Ethernet.h>

byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFA, 0xDE }; //Arduino Rx MAC Address
byte ip[] = { 192, 168, 1, 175 };                    //Arduino Rx IP Address
byte gw[] = { 192, 168, 1, 252 };                     //default gateway
byte subnet[] = { 255, 255, 255, 0 }; 
byte targetIp[] = { 192, 168, 1, 65 };  //PC's IP Address

#define MAX_SIZE 100

Client client(targetIp,8000);

int incomingByte = 0;      // for incoming serial data


void setup()
{
  Ethernet.begin(mac, ip, gw, subnet);
  Serial.begin(38400);   // opens serial port, sets data rate to 38400 bps
  client.connect();      //connect to specified IP and port
}

void loop()
{
  if(Serial.available() > 0) {
            // read the incoming byte:
       incomingByte = Serial.read();
         //client.connect();
         //delay(10);
    if(client.connected()) {   
         client.write((uint8_t *)&incomingByte,MAX_SIZE); //send TCP packet to targetIp
         }
   } 
  
  if (client.available()) {
    char c = client.read();
  }
  
  if (!client.connected()) {
    client.stop();
    for(;;)
      ;
  }
 
 
}

Have a look through this sight.

You may find something there that can help you, like sample code.

:slight_smile:

InvalidApple, thanks for your reply.but, unfortunately it doesn't give me much help.
I've tried running the code, monitor through wireshark, the arduino keeps sending "blackjack port 1025" to my PC, not the data I expected to see. If you could suggest me on the code I posted earlier, it would be nice. :slight_smile:

I don't really have experience in Ethernet communication, but I did find someone with a working example...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1254063613

You should try and modify this example to the text/IP addresses/transfer rate that you want.

I found it by searching for Ethernet blackjack.

There are lots of working examples out there, see if you can spot the difference between your code and theirs.

:slight_smile: