fn socket_server() {
    let server = TcpListener::bind("127.0.0.1:36959").unwrap();
    for stream in server.incoming() {
        thread::spawn (move || {
            let mut websocket = accept(stream.unwrap()).unwrap();
            loop {
                let msg = websocket.read_message().unwrap();
                //Handle only string
                if msg.is_text() {
                    let text = msg.to_text().unwrap();
                    match process_message(text, &mut websocket) {
                        Ok(_) => {},
                        Err(v) => {
                            websocket.write_message(Message::from(format!(r#"{{"action": "alert", "msg": "{}"}}"#, v))).ok();
                        }
                    };
                }
            }
        });
    }
}
//Create socket server coz webview API uses UI thread
Create socket server coz webview API uses UI thread
Create socket server coz webview API uses UI thread
fn socket_server() {
    let server = TcpListener::bind("127.0.0.1:36959").unwrap();
    for stream in server.incoming() {
        thread::spawn (move || {
            let mut websocket = accept(stream.unwrap()).unwrap();
            loop {
                let msg = websocket.read_message().unwrap();
                //Handle only string
                if msg.is_text() {
                    let text = msg.to_text().unwrap();
                    match process_message(text, &mut websocket) {
                        Ok(_) => {},
                        Err(v) => {
                            websocket.write_message(Message::from(format!(r#"{{"action": "alert", "msg": "{}"}}"#, v))).ok();
                        }
                    };
                }
            }
        });
    }
}
fn socket_server ( ) { let server = TcpListener :: bind ( " " ) . unwrap ( ) ; for stream in server . incoming ( ) { thread :: spawn ( move | | { let mut websocket = accept ( stream . unwrap ( ) ) . unwrap ( ) ; loop { let msg = websocket . read_message ( ) . unwrap ( ) ; //Handle only string if msg . is_text ( ) { let text = msg . to_text ( ) . unwrap ( ) ; match process_message ( text , & mut websocket ) { Ok ( _ ) => { } , Err ( v ) => { websocket . write_message ( Message :: from ( format ! ( r#"{{"action": "alert", "msg": "{}"}}"# v ) ) ) . ok ( ) ; } } ; } } } ) ; } }
Create socket server coz webview API uses UI thread
Create socket server coz webview API uses UI thread