2019-06-30 16:11:55 +02:00
|
|
|
import net
|
|
|
|
|
2019-07-01 14:55:45 +02:00
|
|
|
fn test_socket() {
|
2019-07-20 05:51:45 +02:00
|
|
|
// server := net.listen(8080) or {
|
|
|
|
// println(err)
|
|
|
|
// return
|
|
|
|
// }
|
2019-07-01 14:55:45 +02:00
|
|
|
// println(server)
|
2019-07-20 05:51:45 +02:00
|
|
|
// client := net.dial('127.0.0.1', 8080) or {
|
|
|
|
// println(err)
|
|
|
|
// return
|
|
|
|
// }
|
2019-07-01 14:55:45 +02:00
|
|
|
// println(client)
|
2019-07-20 05:51:45 +02:00
|
|
|
// socket := server.accept() or {
|
|
|
|
// println(err)
|
|
|
|
// return
|
|
|
|
// }
|
2019-07-01 14:55:45 +02:00
|
|
|
// println(socket)
|
2019-07-20 05:51:45 +02:00
|
|
|
//
|
2019-07-02 17:25:21 +02:00
|
|
|
// message := 'Hello World'
|
2019-07-22 16:51:33 +02:00
|
|
|
// socket.send(message.str, message.len)
|
2019-07-02 17:25:21 +02:00
|
|
|
// println('Sent: ' + message)
|
2019-07-20 05:51:45 +02:00
|
|
|
//
|
2019-07-02 17:25:21 +02:00
|
|
|
// bytes := client.recv(1024)
|
|
|
|
// println('Received: ' + tos(bytes, message.len))
|
2019-07-20 05:51:45 +02:00
|
|
|
//
|
2019-07-01 14:55:45 +02:00
|
|
|
// server.close()
|
|
|
|
// client.close()
|
|
|
|
// socket.close()
|
2019-06-30 16:11:55 +02:00
|
|
|
}
|