Hi all, I want use udp socket, but example in rust.lang.org is not work.
I do that, but have error in variable err , and I don't understand what I doing wrong...
This is my code:
use std::net::UdpSocket;
use std::net::
fn in_i32()->i32{
let mut stdin = std::io::stdin();
let input:&mut String = &mut String::new();
input.clear();
stdin.read_line(input);
let x = input.trim().to_string().parse::<i32>().unwrap();
return x;
}
fn main() {
let port = 12345;
let mut socket = UdpSocket::bind("192.168.1.225:2525");
if socket.is_err() {
let err = socket.is_err();
println!("failed to read from stdin : {}", err);
let y = in_i32();
return;
}
let mut buf = [0,3];
for i in 0..buf.len(){
buf[i]=i;
println!("{}",buf[i]);
}
//socket.send_
socket.unwrap().send_to(&[7], ("127.0.0.1", 23451)).unwrap();
let y = in_i32();
}
.unwrap() will give you an error message specific to what is actually stopping rust from binding to that port that we can use to diagnose what's happening.
It seems the OS is returning an "InvalidInput" error message, I'm really not sure what that means in your case though. The code works correctly for my machine, I would suggest opening an issue on rust-lang/rust stating that you're getting WSAEINVAL/10022/InvalidInput error on binding a UdpSocket. I suspect this is some sort of error with rust on windows.
option.rs is the file which defines the Option type on the rust build machine. The error message is just trying to be helpful in debugging, while not really being helpful. I would suggest opening an issue on the rust github repository as stated earlier.