我设法连接到TCP服务器并通过TCPStream
发送问候消息。如果成功,我要返回TCPStream
:
pub fn connect_to_tcpserver(&mut self) -> bool {
let mut core = Core::new().unwrap();
let handle = core.handle();
let address = "127.0.0.1:2323".parse().expect("Unable to parse address");
let connection = TcpStream::connect(&address, &handle);
let client = connection.and_then(|mut tcp_stream| {
tcp_stream.write(b"Hello");
Ok(())
});
core.run(client).expect("Unable to run the event loop");
return true;
}
在这种情况下如何返回tcp_stream
变量?
答案 0 :(得分:0)
AVDictionary *d = NULL;
av_dict_set(&d, "foo", "bar", 0);
frame->metadata = d;
已经返回了Players = {0: "Quit",
1: "Player 1",
2: "Player 2",
3: "Player 3"
}
exits = {0: {"Q": 0},
1: {"W": 2, "E": 3, "N": 5, "S": 4, "Q": 0},
2: {"N": 5, "Q": 0},
3: {"W": 1, "Q": 0},
4: {"N": 1, "W": 2, "Q": 0},
5: {"W": 2, "S": 1, "Q": 0}}
avabilablePlayer = ",".join(list(Players.values()))
print(avabilablePlayer)
direction = input("Available Players are " + avabilablePlayer + " ").upper()
player_index = None
for key, value in Players.items():
if direction == value.upper():
player_index = key
break
if player_index is None:
print('Invalid Player')
else:
dict_key = exits.get(player_index)
print(dict_key)
,所以我刚返回了
core.run