tcp client

i'm using arduino UNO and w5100 ethernet shield. i'm trying to connect my ethernet shield to this software i downloaded ( SocketTest v3.00) to do some communication between the server (sockettest) and my shield (client).The shield jack was connected to my router. I created a server under the ip address of my laptop. i uses the telnet client example but it just can't connect to my server on the sockettest. This was the first time i'm doing tcp/ip , does anyone had done similar project or could guide me on this.

sockettest -http://sockettest.sourceforge.net/

UNO -Arduino Uno Rev3 — Arduino Official Store

Ethernet shield -http://www.hobbytronics.co.uk/arduino-wiznet-shield

Here the code

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

byte mac[] = {
  0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED
};
IPAddress ip(192, 168, 1, 220);// shield ip


IPAddress server(192, 168, 1, 37); // my computer ip

EthernetClient client;

void setup() {
  // start the Ethernet connection:
  Ethernet.begin(mac, ip);// Open serial communications and wait for port to open:
  
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  // give the Ethernet shield a second to initialize:
  delay(1000);
  Serial.println("connecting...");

  // if you get a connection, report back via serial:
  if (client.connect(server, 10002)) {
    Serial.println("connected");
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
}

void loop() {
  // if there are incoming bytes available
  // from the server, read them and print them:
  if (client.available()) {
    char c = client.read();
    Serial.print(c);
  }

  // as long as there are bytes in the serial queue,
  // read them and send them out the socket if it's open:
  while (Serial.available() > 0) {
    char inChar = Serial.read();
    if (client.connected()) {
      client.print(inChar);
    }
  }

  // if the server's disconnected, stop the client:
  if (!client.connected()) {
    Serial.println();
    Serial.println("disconnecting.");
    client.stop();
    // do nothing:
    while (true);
  }
}

I've never used that particular piece of software, but why are you trying to connect to port 10002?
Can you verify that your computer is listening on that port?

Pieter

turn off windows firewall for the test

i have try both port 23 and 80 but i still can't get it to connect to the server.i'm unsure on how to set the port. could the selecting of the port affecting the connection . how can i check on the port that my computer is currently listening to.

yuanqing:
i have try both port 23 and 80 but i still can't get it to connect to the server.i'm unsure on how to set the port. could the selecting of the port affecting the connection .

You can't connect to a port that's not open.

yuanqing:
how can i check on the port that my computer is currently listening to.

LMGTFY

Why are you using sockettest? Why not just connect to an actual server?

Pieter

sockettest was the first software i found on the net . i done a project on the sockettest using socketest as a client connect to an arduino server and it's working fine.

i still don't understand this part , connecting to actual server . Are you talking about a web server or tcp server.

Web servers use the HTTP protocol to communicate with clients. HTTP is built on top of TCP. In order to communicate with a web server, you first need to establish a TCP connection (on port 80 for HTTP, port 443 for HTTPS), and then send HTTP requests (text) over the TCP connection.

What do you actually want to do with the Ethernet shield? You want to test TCP sockets, so I'm guessing your project requires you to connect to an actual server of some sort over TCP.

Pieter

my project is about sockettest as my server , my arduino ethernet shield as my client connection . Using client to connect to server , i'm think using some LED to test(connect to my client). But the client side just couldn't connect to my server. i'm trying different open port now . Do you have any tips or suggestion on doing this .

my motto here under the line is a tip for you

"write a PC program for it and if it works, port it to arduino. I recommend Java with Eclipse IDE"

yuanqing:
my project is about sockettest as my server , my arduino ethernet shield as my client connection . Using client to connect to server , i'm think using some LED to test(connect to my client). But the client side just couldn't connect to my server. i'm trying different open port now . Do you have any tips or suggestion on doing this .

But why? What is the point of connecting to sockettest? It doesn't seem to do anything useful other that checking the TCP connection and sending some text data.

What port is your sockettest server running at?

Juraj:
my motto here under the line is a tip for you

"write a PC program for it and if it works, port it to arduino. I recommend Java with Eclipse IDE"

I don't see the added benefit of wasting time on writing a Java program first. The Ethernet libraries are very Arduino-specific, and they are known to work. If you have a TCP server listening on port 80 on 192.168.1.37, you can just connect the Arduino to this IP on this port, and it works.
The point here is to test if sockettest is actually working. Try using sockettest TCP client on one computer, and connect to a sockettest TCP server on a second computer on the same network.

Pieter

My plan was to start with a simple TCP/IP server and client. socktest was the first software i found online, after trying out i realised it was easy to use, so i decided to stick with socket test. I was planning to using port 23 as i was doing a tcp server and client.

I just realised that the Rj-45 jack on the Ethernet shield only light up green led, the orange led didn't light up. Could it mean that my cable is faulty ?

port 23 is telnet. you could tell us that you want telnet. and you say that arduino as server was working, so the cable is ok. or?

Sorry for all the inconvenience . I managed to get it to work by using another labtop . i feel that it might be my computer setting that was affecting it, as i haven't look it it yet.

thanks alot Juraj and PieterP for all the guidance and information.