Jump to content

TCP/IP client for Tiva C connected Launchpad

Recommended Posts

Hello Gentlemen,


I'm trying to develop a TCP/IP client with the new TI Connected LaunchPad board but I have some problem with the code that I couldn't figure out and maybe someone can give me a hand, here is the code (based on the Web client example but with some modifications):

#include <Ethernet.h>

// Enter a MAC address for your controller below.
byte mac[] = { 0x00, 0x1F, 0xB0, 0x02, 0xFE, 0x30 };
IPAddress ipLocal(169,254,41,200);
IPAddress server(169,254,41,198);

unsigned int localPort = 8080;      // local port to listen on
char SendBuffer[] = "Something to send\n";        //test data
char ReceiveBuffer[64] = " ";        //receive buffer

// Initialize the Ethernet client library
// with the IP address and port of the server
// that you want to connect to (port 80 is default for HTTP):
EthernetClient client;

void setup() {
  //start the Ethernet
  Ethernet.begin(mac,ipLocal, server);
  //Connect to server
  client.connect(server, localPort);
  //start the serial library:
  Serial.println("\n\nTCP/IP Client setup");
  // start the Ethernet connection:
  if (Ethernet.begin(mac) == 0) {
    Serial.println("Failed to configure Ethernet using DHCP");
    // no point in carrying on, so do nothing forevermore:
  // print your local IP address:
  Serial.print("My IP address: ");
  for (byte thisByte = 0; thisByte < 4; thisByte++) {
    // print the value of each byte of the IP address:
    Serial.print(Ethernet.localIP()[thisByte], DEC);
  Serial.print("connecting to server\n");

  // if you get a connection, report back via serial:
  if (client.connect(server, localPort)) {
    Serial.println("connected to");
    // Make a HTTP request:
    //client.println("GET /search?q=arduino HTTP/1.0");
  else {
    // kf 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();

  // if the server's disconnected, stop the client:
  if (!client.connected()) {

    // do nothing forevermore:
//End of code

On the serial monitor it displays "TCP/IP Client setup" then stops, when I try to find the board using "arp -a" command from the windows cmd it shows nothing about the board (neither the MAC nor the IP address I have assigned to it), tried to connect to the board using a small sockets example written in C++ and for sure nothing happened (just to make sure windows networking utilities aren't screwed).  


Thanks in advance folks :)

Link to post
Share on other sites



if you have router with DHCP, you can try  Ethernet.begin(0); and not  Ethernet.begin(mac,ipLocal, server);

It's work perfectly !

Do not use:

// start the Ethernet connection:

//  if (Ethernet.begin(mac) == 0) {
//    Serial.println("Failed to configure Ethernet using DHCP");
//    // no point in carrying on, so do nothing forevermore:
//    while(true);

Link to post
Share on other sites
  • 1 month later...
Thanks JCR for the information, quite useful one especially with a newbie to Energia syntax like me, much appreciated.


Actually I'm having another problem with this piece of firmware and you might be able to help me solve it, when I turn down the client app on the PC side and re-run it the server isn't able to establish a connection and I need to restart the board to establish a link, though the board is still pingable (still I can ping), have a look on the code and let me know your opinion:


#include <Ethernet.h>

#include <EthernetServer.h>


EthernetServer server(8888);

boolean alreadyConnected = false; // whether or not the client was connected previously


char TxBuffer[15] = "something here\n";

err_t error = 0;


void setup() {

  // initialize the ethernet device


  // start listening for clients







  Serial.print("Chat server address:");




void loop() {

  // wait for a new client:

  EthernetClient client = server.available();


  // when the client sends the first byte, say hello:

  if (client) {

    if (!alreadyConnected) {

      // clead out the input buffer:


      Serial.println("We have a new client");

      //client.println("Hello, client!"); 

      alreadyConnected = true;



    if (client.available() > 0) {

      // read the bytes incoming from the client:

      char RxBuffer = client.read();


      // echo the bytes back to the client:






Thanks again for the help and have a good day.

Link to post
Share on other sites


you must read the example: EthernetWebServer.ino  in energia Ethernet  examples.

and in your file you must close the connection in the main Loop:

void loop(){
  client = server.available();
if (client){
    your program..............
    // close the connection:
}// end if (client)
}// end Main Loop
Link to post
Share on other sites
  • 2 months later...

Hello JCR,


Sorry for the late reply, first thanks for the help, much appreciated.

Second, it doesn't work, actually if I put the "client.stop()" this way in the code it kills the whole connection with the client.


I have tried also the "client.available()" and nothing as well, will keep digging and update the post with anything new.

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...