mirror of
https://github.com/vlang/v.git
synced 2025-08-04 02:07:28 -04:00
examples: fix net_udp_server_and_client.v with latest V and latest net
module (listen on 0.0.0.0, and dial to 127.0.0.1) (#19564)
This commit is contained in:
parent
d851bbbdca
commit
5f1e6815cd
@ -12,7 +12,7 @@ fn main() {
|
|||||||
mut buf := []u8{len: 100}
|
mut buf := []u8{len: 100}
|
||||||
if is_server {
|
if is_server {
|
||||||
println('UDP echo server, listening for udp packets on port: ${port}')
|
println('UDP echo server, listening for udp packets on port: ${port}')
|
||||||
mut c := net.listen_udp(':${port}')!
|
mut c := net.listen_udp('0.0.0.0:${port}')!
|
||||||
for {
|
for {
|
||||||
read, addr := c.read(mut buf) or { continue }
|
read, addr := c.read(mut buf) or { continue }
|
||||||
println('received ${read} bytes from ${addr}')
|
println('received ${read} bytes from ${addr}')
|
||||||
@ -23,7 +23,7 @@ fn main() {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
println('UDP client, sending packets to port: ${port}.\nType `exit` to exit.')
|
println('UDP client, sending packets to port: ${port}.\nType `exit` to exit.')
|
||||||
mut c := net.dial_udp('localhost:${port}')!
|
mut c := net.dial_udp('127.0.0.1:${port}')!
|
||||||
for {
|
for {
|
||||||
mut line := os.input('client > ')
|
mut line := os.input('client > ')
|
||||||
match line {
|
match line {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user