Struct sfml::network::TcpSocket
[−]
[src]
pub struct TcpSocket {
// some fields omitted
}Specialized socket using the TCP protocol
Methods
impl TcpSocket[src]
fn new() -> Option<TcpSocket>
Create a new TCP socket
Return Some(TcpSocket) or None
fn set_blocking(&mut self, blocking: bool)
Set the blocking state of a TCP listener
In blocking mode, calls will not return until they have completed their task. For example, a call to sfUDPSocket_receive in blocking mode won't return until new data was actually received. In non-blocking mode, calls will always return immediately, using the return code to signal whether there was data available or not. By default, all sockets are blocking.
Arguments
- blocking - true to set the socket as blocking, false for non-blocking
fn is_blocking(&self) -> bool
Tell whether a TCP socket is in blocking or non-blocking mode
Return true if the socket is blocking, false otherwise
fn get_local_port(&self) -> u16
Get the port to which a TCP socket is bound locally
If the socket is not bound to a port, this function returns 0.
Return the port to which the socket is bound
fn get_remote_address(&self) -> IpAddress
Get the address of the connected peer of a TCP socket
It the socket is not connected, this function returns sfIpAddress_None.
Return the address of the remote peer
fn get_remote_port(&self) -> u16
Get the port of the connected peer to which a TCP socket is connected
If the socket is not connected, this function returns 0.
Return the remote port to which the socket is connected
fn connect(&self, host: &IpAddress, port: u16, timeout: Time) -> SocketStatus
Connect a TCP socket to a remote peer
In blocking mode, this function may take a while, especially if the remote peer is not reachable. The last parameter allows you to stop trying to connect after a given timeout. If the socket was previously connected, it is first disconnected.
Arguments
- remoteAddress - Address of the remote peer
- remotePort - Port of the remote peer
- timeout - Maximum time to wait
fn disconnect(&mut self)
Disconnect a TCP socket from its remote peer
This function gracefully closes the connection. If the socket is not connected, this function has no effect.
fn send(&self, data: &[i8]) -> SocketStatus
Send raw data to the remote peer of a TCP socket
Arguments
- data - Vector of the sequence of bytes to send
Return the status code
fn receive(&self, max_size: size_t) -> (Vec<i8>, SocketStatus, size_t)
Receive raw data from the remote peer of a TCP socket
In blocking mode, this function will wait until some bytes are actually received. This function will fail if the socket is not connected.
Arguments
- size - Maximum number of bytes that can be received
Return a tuple containing the size read, a vector width data and the socket status
fn send_packet(&self, packet: &Packet) -> SocketStatus
Send a formatted packet of data to the remote peer of a TCP socket
Arguments
- packet - Packet to send
Return the socket status
fn receive_packet(&self) -> (Packet, SocketStatus)
Receive a formatted packet of data from the remote peer
In blocking mode, this function will wait until the whole packet has been received. This function will fail if the socket is not connected.
Return a packet and a socket status