Methods

The Winsock control has only a handful of methods. With a couple of exceptions, most of these method names mirror their Winsock equivalents. The method to read pending data is named GetData. Normally you would call the GetData method once the DataArrival event is triggered, notifying you that data has arrived. The method for sending data is named SendData. Additionally, a method named PeekData is similar to calling the Winsock recv function with the MSG_PEEK option. As always, message peeking is evil and should be avoided at all costs. Table 15-3 lists the available methods with their parameters. The methods themselves will be discussed in more detail in the client and server example sections later in this chapter.

Table 15-3. Winsock control methods

Method Parameters Return Value Description
Accept RequestID Void For TCP connections only. Use this method to accept incoming connections when handling a ConnectionRequest event.
Bind LocalPort
LocalIP
Void Binds the socket to the given local port and IP. Use Bind if you have multiple network adapters. Bind must be called before Listen.
Close None Void Closes the connection or the listening socket.
Connect RemoteHost
RemotePort
Void Establishes a TCP connection to the given RemotePort on the given RemoteHost number.
GetData Data
Type
MaxLen
Void Retrieves the current data pending. The Type and MaxLen parameters are optional. The Type parameter defines the type of the data to be read. The MaxLen parameter specifies how many bytes or characters to retrieve. GetData ignores the MaxLen parameter for types other than byte array and string.
Listen None Void Creates a socket and places it in listen mode. Listen is used only for TCP connections.
PeekData Data
Type
MaxLen
Void Behaves exactly like GetData except that the data is not removed from the system's buffer.
SendData Data Void Sends data to the remote computer. If a UNICODE string is passed, it will be converted to an ANSI string first. Always use a byte array for binary data.



Network Programming for Microsoft Windows
Linux Server Hacks, Volume Two: Tips & Tools for Connecting, Monitoring, and Troubleshooting
ISBN: 735615799
EAN: 2147483647
Year: 1998
Pages: 159

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net