1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00
v/vlib/net/socket_test.v

33 lines
685 B
V
Raw Normal View History

import net
2019-06-30 17:11:55 +03:00
2019-07-01 15:55:45 +03:00
fn test_socket() {
server := net.listen(0) or {
panic(err)
}
server_port := server.get_port()
client := net.dial('127.0.0.1', server_port) or {
panic(err)
}
socket := server.accept() or {
panic(err)
}
message := 'Hello World'
2019-11-04 02:38:49 +03:00
socket.send(message.str, message.len) or {
assert false
}
$if debug { println('message send: $message') }
$if debug { println('send socket: $socket.sockfd') }
bytes, blen := client.recv(1024)
received := tos(bytes, blen)
$if debug { println('message received: $received') }
$if debug { println('client: $client.sockfd') }
assert message == received
2019-11-04 02:38:49 +03:00
server.close() or {}
client.close() or {}
socket.close() or {}
}