[][src]Function message_protocol::listen_to_tcp

pub fn listen_to_tcp<T: ToSocketAddrs>(
    bind_to_address: T
) -> Result<Receiver<ClientMessage>, Error>

Listens for TCP on given address asynchronously.

Returns a Reciever which sends messages of the type Message

Example:

let recieve_messages = message_protocol::listen_to_tcp("127.0.0.1:45932")?;
while let Ok(msg) = recieve_messages.recv() {
    println!("from {}", msg.address);
    match msg.message {
        message_protocol::Message::Open => println!("open"),
        message_protocol::Message::Bytes(b) => println!("bytes {:?}", b),
        message_protocol::Message::Close => println!("close"),
     };
 }