pub fn listen(
        &mut self,
        laminar_config: LaminarConfig,
        socket_address: SocketAddr,
        webrtc_listen_address: Option<SocketAddr>,
        public_webrtc_address: Option<SocketAddr>,
    ) {
        let mut server_socket = {
            let webrtc_listen_address = webrtc_listen_address.unwrap_or_else(|| {
                let mut listen_addr = socket_address;
                listen_addr.set_port(socket_address.port() + 1);
                listen_addr
            });
            let public_webrtc_address = public_webrtc_address.unwrap_or(webrtc_listen_address);
            let socket = block_on(NaiaServerSocket::listen(
                socket_address,
                webrtc_listen_address,
                public_webrtc_address,
            ));

            if let Some(ref conditioner) = self.link_conditioner {
                socket.with_link_conditioner(conditioner)
            } else {
                socket
            }
        };
        
        // all packets from naia, regardless of src_addr, are sent to laminar, which is responsible
        // for assigning them to virtual connections, channels, etc.

        // naia_packet_tx and naia_payload_rx are moved to async tasks below
        let (naia_packet_tx, naia_packet_rx) = unbounded::<NaiaPacket>();
        let (naia_payload_tx, naia_payload_rx ) = unbounded::<NaiaPacket>();
        
        let mut naia_sender = server_socket.get_sender();

        self.manager = Some(LaminarConnectionManager::new(
            LaminarDatagramSocketForNaia {
                bind_address: socket_address,
                naia_packet_receiver: naia_packet_rx,
                naia_payload_sender: naia_payload_tx,
            },
            laminar_config
        ));

        let receiver_task = self.task_pool.spawn(async move {
            loop {
                // when naia-socket receives a packet, deliver it to laminar channel
                match server_socket.receive().await {
                    Ok(naia_packet) => {
                        let address = naia_packet.address();
                        if let Err(error) = naia_packet_tx.send(naia_packet) {
                            log::error!("Error processing naia packet from {} - {}", address, error)
                        }
                    }
                    Err(error) => {
                        log::error!("Server Receive Error: {}", error);
                    }
                }
            }
        });

        let sender_task = self.task_pool.spawn(async move {
            loop {
                // when laminars publishes a packet to send, give it to naia-socket to send
                match naia_payload_rx.recv() {
                    Ok(naia_packet) => {
                        if let Err(error) = naia_sender.send(naia_packet).await {
                            log::error!("Error sending payload to naia_sender {}", error);
                        }
                    },
                    Err(CrossbeamRecvError) => {
                        log::error!("Crossbeam RecvError in sender_task! Oh dear");
                        assert!(false, "Crossbeam RecvError in sender_task!");
                    }
                }
            }
        });

        self.listeners.push(ServerListener {
            socket_address,
            tasks: vec![ receiver_task, sender_task ],
        });
    }
/// The 3 listening addresses aren't strictly necessary, you can put the same IP address with
/// a different port for the socket address; Unless you have some configuration issues with 
/// public and private addresses that need to be connected to.
/// They also aren't necessary if you're using UDP, so you can put anything if that's the case.
The 3 listening addresses aren't strictly necessary, you can put the same IP address with
a different port for the socket address; Unless you have some configuration issues with
public and private addresses that need to be connected to.
They also aren't necessary if you're using UDP, so you can put anything if that's the case.
The 3 listening addresses aren ' t strictly necessary you can put the same IP address with a different port for the socket address ; Unless you have some configuration issues with public and private addresses that need to be connected to . They also aren ' t necessary if you ' re using UDP so you can put anything if that ' s the case .
pub fn listen(
        &mut self,
        laminar_config: LaminarConfig,
        socket_address: SocketAddr,
        webrtc_listen_address: Option<SocketAddr>,
        public_webrtc_address: Option<SocketAddr>,
    ) {
        let mut server_socket = {
            let webrtc_listen_address = webrtc_listen_address.unwrap_or_else(|| {
                let mut listen_addr = socket_address;
                listen_addr.set_port(socket_address.port() + 1);
                listen_addr
            });
            let public_webrtc_address = public_webrtc_address.unwrap_or(webrtc_listen_address);
            let socket = block_on(NaiaServerSocket::listen(
                socket_address,
                webrtc_listen_address,
                public_webrtc_address,
            ));
            if let Some(ref conditioner) = self.link_conditioner {
                socket.with_link_conditioner(conditioner)
            } else {
                socket
            }
        };
        // all packets from naia, regardless of src_addr, are sent to laminar, which is responsible
        // for assigning them to virtual connections, channels, etc.
        // naia_packet_tx and naia_payload_rx are moved to async tasks below
        let (naia_packet_tx, naia_packet_rx) = unbounded::<NaiaPacket>();
        let (naia_payload_tx, naia_payload_rx ) = unbounded::<NaiaPacket>();
        let mut naia_sender = server_socket.get_sender();
        self.manager = Some(LaminarConnectionManager::new(
            LaminarDatagramSocketForNaia {
                bind_address: socket_address,
                naia_packet_receiver: naia_packet_rx,
                naia_payload_sender: naia_payload_tx,
            },
            laminar_config
        ));
        let receiver_task = self.task_pool.spawn(async move {
            loop {
                // when naia-socket receives a packet, deliver it to laminar channel
                match server_socket.receive().await {
                    Ok(naia_packet) => {
                        let address = naia_packet.address();
                        if let Err(error) = naia_packet_tx.send(naia_packet) {
                            log::error!("Error processing naia packet from {} - {}", address, error)
                        }
                    }
                    Err(error) => {
                        log::error!("Server Receive Error: {}", error);
                    }
                }
            }
        });
        let sender_task = self.task_pool.spawn(async move {
            loop {
                // when laminars publishes a packet to send, give it to naia-socket to send
                match naia_payload_rx.recv() {
                    Ok(naia_packet) => {
                        if let Err(error) = naia_sender.send(naia_packet).await {
                            log::error!("Error sending payload to naia_sender {}", error);
                        }
                    },
                    Err(CrossbeamRecvError) => {
                        log::error!("Crossbeam RecvError in sender_task! Oh dear");
                        assert!(false, "Crossbeam RecvError in sender_task!");
                    }
                }
            }
        });
        self.listeners.push(ServerListener {
            socket_address,
            tasks: vec![ receiver_task, sender_task ],
        });
    }
pub fn listen ( & mut self , laminar_config : LaminarConfig , socket_address : SocketAddr , webrtc_listen_address : Option < SocketAddr > , public_webrtc_address : Option < SocketAddr > , ) { let mut server_socket = { let webrtc_listen_address = webrtc_listen_address . unwrap_or_else ( | | { let mut listen_addr = socket_address ; listen_addr . set_port ( socket_address . port ( ) + 1 ) ; listen_addr } ) ; let public_webrtc_address = public_webrtc_address . unwrap_or ( webrtc_listen_address ) ; let socket = block_on ( NaiaServerSocket :: listen ( socket_address , webrtc_listen_address , public_webrtc_address , ) ) ; if let Some ( ref conditioner ) = self . link_conditioner { socket . with_link_conditioner ( conditioner ) } else { socket } } ; // all packets from naia, regardless of src_addr, are sent to laminar, which is responsible // for assigning them to virtual connections, channels, etc. // naia_packet_tx and naia_payload_rx are moved to async tasks below let ( naia_packet_tx , naia_packet_rx ) = unbounded :: < NaiaPacket > ( ) ; let ( naia_payload_tx , naia_payload_rx ) = unbounded :: < NaiaPacket > ( ) ; let mut naia_sender = server_socket . get_sender ( ) ; self . manager = Some ( LaminarConnectionManager :: new ( LaminarDatagramSocketForNaia { bind_address : socket_address , naia_packet_receiver : naia_packet_rx , naia_payload_sender : naia_payload_tx , } , laminar_config ) ) ; let receiver_task = self . task_pool . spawn ( async move { loop { // when naia-socket receives a packet, deliver it to laminar channel match server_socket . receive ( ) . await { Ok ( naia_packet ) => { let address = naia_packet . address ( ) ; if let Err ( error ) = naia_packet_tx . send ( naia_packet ) { log :: error ! ( " " address error ) } } Err ( error ) => { log :: error ! ( " " error ) ; } } } } ) ; let sender_task = self . task_pool . spawn ( async move { loop { // when laminars publishes a packet to send, give it to naia-socket to send match naia_payload_rx . recv ( ) { Ok ( naia_packet ) => { if let Err ( error ) = naia_sender . send ( naia_packet ) . await { log :: error ! ( " " error ) ; } } , Err ( CrossbeamRecvError ) => { log :: error ! ( " " ) ; assert ! ( false " " ) ; } } } } ) ; self . listeners . push ( ServerListener { socket_address , tasks : vec ! [ receiver_task sender_task ] , } ) ; }
The 3 listening addresses aren't strictly necessary, you can put the same IP address with
a different port for the socket address; Unless you have some configuration issues with
public and private addresses that need to be connected to.
The 3 listening addresses aren ' t strictly necessary you can put the same IP address with a different port for the socket address ; Unless you have some configuration issues with public and private addresses that need to be connected to .
&mut self
laminar_config
LaminarConfig
socket_address
SocketAddr
webrtc_listen_address
Option<SocketAddr>
public_webrtc_address
Option<SocketAddr>