Generic TCP Server

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
Generic TCP Server

Overview 

The Generic TCP Server example demonstrates how to build a TCP server application. Once you connect to the demo server, it will echo your keystrokes back to you after converting the characters to UPPER CASE. 

Instructions 

  1. Connect the programmed demo board to a computer either directly or through a router. For Ethernet, a direct connection may require a crossover cable; for WiFi, the board may need to be in AdHoc mode to establish a direct connection.
  2. Determine the IP address of the demo board. This can be done several different ways.
    1. If you are using a demo setup with an LCD display (e.g. Explorer 16 or PICDEM.net 2), the IP address should be displayed on the second line of the display.
    2. Open the Microchip TCP/IP Discoverer from the start menu. Press the "Discover Devices" button to see the addresses and host names of all devices with the Announce Protocol enabled on your network. You may have to configure your computer's firewall to prevent it from blocking UDP port 30303 for this solution.
    3. If your board is connected directly with your computer with a crossover cable:
      1. Open a command/DOS prompt and type 'ipconfig'. Find the network adaptor that is connected to the board. The IP address of the board is located in the 'Default Gateway' field
      2. Open up the network status for the network adaptor that connects the two devices. This can be done by right clicking on the network connection icon in the network settings folder and select 'status' from the menu. Find the 'Default Gateway' field.
  3. Open a command/DOS prompt. Type "telnet ip_address 9760" where ip_address is the IP address that you got from step 2 and 9760 is the TCP port chosen for the Generic TCP Server implementation.
  4. As you type characters, they will be echoed back in your command prompt window in UPPER CASE.
  5. Press Escape to end the demo.

Description 

The GenericTCPServer demo implements a task function with 3 states. In the first state, SM_HOME, the task will attempt to open a TCP server socket. This socket will use a TCP_PURPOSE_GENERIC_TCP_SERVER socket type from the TCP socket structure that was initialized in your configuration files. It will also listen on TCP port 9760 (defined by the macro SERVER_PORT). 

Once the socket has been successfully opened, the task function will enter the SM_LISTENING state. In this state, the task will always return unless a client has connected to it (by establishing a telnet connection on port 9760). Once a client has connected to the server, the server will read received data from the TCP socket's RX buffer, convert it to upper case, and write it to the TCP socket's TX buffer. 

If an Escape character is received, the server will enter the SM_CLOSING state. In this state, it will close the server socket to break the current connection. The server will then re-enter the SM_HOME state, where it will reopen the TCP_PURPOSE_GENERIC_TCP_SERVER socket to listen for new connections.

Functions
 
Name 
Description 
 
Implements a simple ToUpper TCP Server. 
Topics
Name 
Description 
The following table lists macros in this documentation. 
Macros
 
Name 
Description 
 
Defines which port the server will listen on 
Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.