Generic TCP Client

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
Generic TCP Client

Overview 

The Generic TCP Client provides an example of how to build an HTTP client (or any other TCP client) using the Microchip TCP/IP Stack. It will print out the results from a search engine query to the PIC's UART module. The result data can be viewed on a PC terminal. 

Instructions 

  1. Connect the programmed demo board to a router that is connected to the Internet.
  2. Connect your PC to your demo board with an RS-232 cable. Open a terminal program like HyperTerminal, and configure it to the following settings: 19200 bps, 8 data bits, No parity, 1 stop bit, No flow control.
  3. Press Button 1 on your demo board (check the BUTTON1_IO macro in the copy of HardwareProfile.h that corresponds to your project to determine which button is Button 1).
  4. Observe the search results for "Microchip" at www.microchip.com on your terminal.

Description 

The Generic TCP Client demo implements a task function with five states. When the board is powered on, the initial state will be set to SM_DONE. This state will wait for the user to press Button 1; when a button-press event occurs, the state will switch to SM_HOME. In the SM_HOME state, the task will attempt to open a TCP client socket. This socket will use a TCP_PURPOSE_GENERIC_TCP_CLIENT socket type from the TCP socket structure that was initialized in your configuration files. The targeted server will be the Google search engine, and the server port will be 80, the port used for HTTP connections. The task will switch the state machine to the SM_SOCKET_OBTAINED state. 

The task will wait in the SM_SOCKET_OBTAINED state until a connection is established with Google or a 5-second timeout elapses. If a timeout occurs, the state will close the socket and change the state back to SM_HOME. Otherwise, it will wait until the TCP buffer can accept 125 bytes of data and then use an HTTP GET to search for the word "Microchip" at the site "microchip.com." Once the GET has been sent, the state will switch to SM_PROCESS_RESPONSE. 

In the SM_PROCESS_RESPONSE state, the task will wait until a response is received or the socket was disconnected. If a response is received, it will print it to the UART. In either case, the task will transition to the SM_DISCONNECT state, where it will close the client socket and return to the SM_DONE state.

Functions
 
Name 
Description 
 
Implements a simple HTTP client (over TCP). 
Topics
Name 
Description 
The following table lists variables in this documentation. 
Variables
 
Name 
Description 
 
Defines the URL to be requested by this HTTP client 
 
Defines the server to be accessed for this application 
 
Note that if HTTPS is used, the ServerName and URL must change to an SSL enabled server. 
Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.