mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
9834ccfcd9
cleanup schannel implementation (drop NT4.0 compatibility, use unicode strings, etc) restore http tests fix socket test: it did not throw before
31 lines
657 B
V
31 lines
657 B
V
import net
|
|
|
|
fn test_socket() {
|
|
mut server := net.listen(0) or {
|
|
panic(err)
|
|
}
|
|
server_port := server.get_port()
|
|
mut client := net.dial('127.0.0.1', server_port) or {
|
|
panic(err)
|
|
}
|
|
mut socket := server.accept() or {
|
|
panic(err)
|
|
}
|
|
|
|
message := 'Hello World'
|
|
socket.send(message.str, message.len)
|
|
$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
|
|
|
|
server.close()
|
|
client.close()
|
|
socket.close()
|
|
}
|