a small device, a file system can be as basic as a structure
whose members each store a file name, a starting address in
memory, and the length of the file stored at that address.
FTP communications travel in TCP segments. A
device that supports FTP must also support TCP and IP.
Moving On
For more information and ideas about network
applications for small systems, a good place to start is my
website’s Embedded Ethernet and Internet Central page
( www.Lvr.com/ethernet.htm), which has code
examples and links to sources for modules with networking support. NV
About the Author
Jan Axelson is the author of Embedded Ethernet and
Internet Complete, USB Complete, and other books about
computer interfacing. Jan’s website is www.Lvr.com
Listing 1. In Visual Basic .NET, you can use the TcpClient class to
communicate with your devices.
‘ Read data from a remote computer over a TCP connection.
Dim networkStream As networkStream =
myTcpClient.GetStream()
If networkStream.CanRead Then
Dim dataReceived(myTcpClient.ReceiveBufferSize) As Byte
‘ Read the networkStream object into a byte buffer.
‘ Read can return anything from 0 to numBytesToRead.
‘ This method blocks until at least one byte is read
‘ or a receive timeout.
Dim numberOfBytesRead As Integer = networkStream.Read _
(dataReceived,
0,
CInt(myTcpClient.ReceiveBufferSize))
Else
MessageBox.Show(“You can’t read data from this
stream.”)
Return
End If
‘ Write data to a remote computer over a TCP connection.
Dim networkStream As networkStream =
myTcpClient.GetStream()
Dim dataToSend(7) As Byte
‘ (Place data to send in the byte array.)
If networkStream.CanWrite Then
networkStream.Write _
(dataToSend,
0,
dataToSend.Length)
Else
MessageBox.Show(“You can’t write data to this stream.”)
End If
MAY 2004
Circle #45 on the Reader Service Card.
Circle #91 on the Reader Service Card.
65