|
Bind the socket to the specified local address and port
number.
Syntax
object.Bind( [LocalAddress],
[LocalPort], [Protocol], [Timeout],
[Options] )
Parameters
- LocalAddress
- An optional string value that specifies the local Internet address
that the socket should be bound to. To bind to any valid network interface
on the local system, specify the address 0.0.0.0. Applications should
only specify a particular address if it is absolutely necessary. In
most cases a local address is not required when establishing a client
connection. If this value is not specified, the LocalAddress
property will be used to determine the default value.
- LocalPort
- An optional integer value that specifies a local port number
that the socket should be bound to. To bind to any available port
number, specify a port number of 0. Applications should only specify
a particular port number if it is absolutely necessary. The maximum
valid port number is 65535. If this argument is not specified, the
LocalPort property will be used to determine the default value.
- Protocol
- An optional integer value that specifies the protocol that should be
used when establishing the connection. If this argument is not specified,
the value of the Protocol property will be used as the default. One
of the following values may be used:
Value |
Description |
swProtocolTcp |
Specifies the Transmission Control Protocol. This protocol
provides a reliable means of communication between two
computers using a client/server architecture. The data is
exchanged as a stream of bytes, with the protocol ensuring that
the data arrives in the same byte order that it was sent,
without duplication or missing data. This protocol is designed
for accuracy and not speed, therefore TCP can sometimes incur
relatively long delays while waiting for out-of-order packets
and the retransmission of data which can make it unsuitable for
some applications such as streaming video or audio. |
swProtocolUdp |
Specifies the User Datagram Protocol. This is a stateless,
peer-to-peer message oriented protocol, with the data sent in
discrete packets. UDP is a simpler network protocol that does
not have the inherent reliability of TCP, but it has less
overhead and is ideal for real-time applications where a
dropped packet is preferable to the delay of waiting for a
packet to be retransmitted. It also supports the broadcasting
of datagrams over local networks, and is commonly used by
services that must exchange a relatively small amount of data
with a large number of clients. |
- Timeout
- An optional integer value that specifies the amount of time until
a blocking operation fails. If this argument is not specified, the
Timeout property will be used to determine the default value.
- Options
- An optional integer value that specifies one or more options
which are to be used when establishing the connection. The value is
created by combining the options using a bitwise Or operator. Note
that if this argument is specified, it will override any property
values that are related to that option.
Value |
Description |
swOptionBroadcast |
This option specifies that broadcasting should be enabled
for datagrams. This option is invalid for stream sockets. |
swOptionDontRoute |
This option specifies default routing should not be used.
This option should not be specified unless absolutely
necessary. |
swOptionKeepAlive |
This option specifies that packets are to be sent to the
remote system when no data is being exchanged to keep the
connection active. This option is only valid for stream
sockets. |
swOptionReuseAddress |
This option specifies the local address can be reused.
This option is commonly used by server applications. |
swOptionNoDelay |
This option disables the Nagle algorithm, which buffers
unacknowledged data and insures that a full-size packet can be
sent to the remote host. |
swOptionInLine |
This option specifies that out-of-band data should be
received inline with the standard data stream. This option is
only valid for stream sockets. |
Return Value
A value of zero is returned if the connection was successful.
Otherwise, a non-zero error code is returned which indicates the
cause of the failure.
Remarks
When this method is called with swProtocolUdp as the
specified protocol, it will immediately create the datagram socket
and bind it to the given address. When this method is called with
swProtocolTcp as the specified protocol, creation of the
socket is deferred until the Connect method is called. For
stream sockets, this method will set the local address, port number
and default options used when the socket is actually created.
See Also
Broadcast Property,
LocalAddress Property,
LocalPort Property,
Timeout Property,
Connect Method,
Disconnect Method
|
|