This article shows how to exchange data via raw TCP connection between Arduino and computer

Demonstration




Source code

- TCP Client: on Arduino

Code:
#include <SPI.h>
#include <Phpoc.h>

//char server_name[] = "domain name"; // Domain name of TCP server
char server_name[] = "192.168.0.3"; // Or IP of TCP server
int server_port = 14701;
PhpocClient client;

void setup() {
  Serial.begin(9600);
  while(!Serial)
    ;

  Serial.println("Connect to TCP Server");

  Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
  //Phpoc.begin();

  if(client.connect(server_name, server_port))
  {
    Serial.println("Connected to server");

    //Send data to server
    client.println("Hello Server!");
  }
  else
    Serial.println("connection failed");
}

void loop() {
  if(client.available())
  {
    //Read data from server
    char c = client.read();
    Serial.print(c);
  }

  if(Serial.available())
  {
    // read the incoming byte:
     char incomingByte = Serial.read();
    //Send data to server
     client.print(incomingByte);
  }

  if(!client.connected())
  {
    Serial.println("disconnected");
    client.stop();
    while(1)
      ;
  }
}




- TCP Server: on Computer

You can use any software which can create TCP Server or program a TCP server by yourself using any programming languages. I can find a lot of sample code on the Internet.

In the video for demonstration, I used ezTerm, a software can create TCP server. You can download it here http://www.eztcp.com/en/download/ezterm.php

Or get sample code here:
- TCP Server Program(Visual Basic) : http://www.eztcp.com/en/download/pds...page=1&cid=235
- TCP Server Program Visual C++(Visual Studio 6.0): http://www.eztcp.com/en/download/pds...page=1&cid=232
- TCP Server Program Visual C++(Visual Studio 2008): http://www.eztcp.com/en/download/pds...page=1&cid=231
- TCP Server Program(Java): http://www.eztcp.com/en/download/pds...page=1&cid=227
- TCP Server Program Linux(Receive 1 Byte): http://www.eztcp.com/en/download/pds...page=1&cid=229
- TCP Server Program Linux(Periodic Transmission): http://www.eztcp.com/en/download/pds...page=1&cid=228

Or find it on the Internet.

If you have any question, feel free to leave a comment.