ChipCenter Questlink
SEARCH CHIPCENTER
Search Type:
Search for:




Knowledge Centers
Product Reviews
Data Sheets
Guides & Experts
News
International
Ask Us
Circuit Cellar Online
App Notes
NetSeminars
Careers
Resources
FAQ
EE Times Network
Electronics Group Sites

AN S-7600A/PIC16F877 JOURNEY


Circuit Cellar Online
THE MAGAZINE FOR COMPUTER APPLICATIONS
Circuit Cellar Online offers articles illustrating creative solutions
and unique applications through complete projects, practical
tutorials, and useful design techniques.

AN S-7600A/PIC16F877 JOURNEY

Lessons from the Trenches Part 4: Road Testing
by Fred Eady

Start ı Janis Joplin School of Programming ı Who or What is Perl? ı Setting Up the Server ı Applying What Weıve Learned ı Internet Engine Client Code ı Get on the ıNet ı Sources and PDF

APPLYING WHAT WEıVE LEARNED

While itıs fresh, letıs put together the Perl code to accept some data from the Internet Engine and spit it right back out. Iıll choose an arbitrary port number of 8080 decimal and use TCP/IP as the protocol and delivery method. When the socket is created, Iıll allow up to 20 Internet Engines to wait in the queue for a connection. When an Internet Engine connects successfully, it will send an ASCII string to the server. The server will, in turn, send back or echo the received ASCII string to the Internet Engine. The communications session will end and wait for another Internet Engine to call in and connect. The application is quite simple and so is the code (see Listing 1 <LINK>).

The LocalAddr and LocalPort constructor options provide the IP address and port number that will be used to bind the socket. I promised 20 Internet Engines in the queue and the listen option performs that action. SOCK_STREAM tells you TCP/IP is in effect. You havenıt been exposed to the reuse option. If reuse is a nonzero number, this constructor option allows the local bind address to be reused should the socket need to be reopened after an error. Iıve been doing or dying all through this article so thereıs nothing new in that line of thought.

Moving to the meat of the Perl code, it looks like I really wrote this in C. Not! After the server socket is created, a never-ending loop is entered. The IO::Socket mechanism has already put the server at Port 8080 in Listen mode. The next task is to accept any incoming connect requests, create a new socket object, and process the communications session.

The new socket object receives data from the Internet Engine. This data can be just about anything as long as it is meaningful to the programmer of the Internet Engine. A receive data buffer of 256 bytes is allocated for this process. This simple example does nothing with the data. It simply resends the contents of the receive buffer back to the remote Internet Engine. When the data is sent, the newly created socket object is closed and the server reverts back to waiting for a new connection request. If anything blows up the program, the final close statement kills the server socket.

PREVIOUSNEXT


Circuit Cellar provides up-to-date information for engineers. Visit www.circuitcellar.com for more information and additional articles.
For subscription information, call (860) 875-2199, subscribe@circuitcellar.com or subscribe online. ıCircuit Cellar, the Magazine for Computer Applications. Posted with permission.
Click here to get your listing up.

Copyright © 2003 ChipCenter-QuestLink
About ChipCenter-Questlink  Contact Us  Privacy Statement   Advertising Information  FAQ