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

examples: add net_udp_server_and_client.v

This commit is contained in:
Delyan Angelov
2021-02-02 10:36:51 +02:00
parent 2c4674eb42
commit d57a9c419d
2 changed files with 52 additions and 8 deletions

View File

@ -3,10 +3,16 @@ module net
import time
const (
udp_default_read_timeout = 30 * time.second
udp_default_write_timeout = 30 * time.second
udp_default_read_timeout = time.second / 10
udp_default_write_timeout = time.second / 10
)
struct UdpSocket {
handle int
l Addr
r ?Addr
}
pub struct UdpConn {
pub mut:
sock UdpSocket
@ -168,12 +174,6 @@ pub fn listen_udp(port int) ?&UdpConn {
}
}
struct UdpSocket {
handle int
l Addr
r ?Addr
}
fn new_udp_socket(local_port int) ?&UdpSocket {
sockfd := socket_error(C.socket(SocketFamily.inet, SocketType.udp, 0)) ?
mut s := &UdpSocket{