Skip to content

net/send-to fails when using net/connect with :datagram #1620

@tttuuu888

Description

@tttuuu888

Hi All,

When writing a UDP client in Janet, using a stream created by net/connect with the net/send-to function results in a "bad stream, expected datagram socket" error.

Problematic Code:

# Server
(def server-stream (net/listen "127.0.0.1" 8001 :datagram))
(def buf (buffer/new 1024))
(net/recv-from server-stream 1024 buf)
(print (string "Recv: " buf))
# Client
(def server-address (net/address "127.0.0.1" 8001 :datagram))
(def client-stream (net/connect "127.0.0.1" 8001 :datagram))
(net/send-to client-stream server-address "Test message")

Error message on Client net/send-to function:

Janet 1.38.0-0aee7765 linux/x64/gcc - '(doc)' for help
repl:1:> <core/socket-address 0x64E73B4870B0>
repl:2:> <core/stream [fd=7]>
repl:3:> error: bad stream, expected datagram socket
  in net/send-to [src/core/net.c] on line 927
  in thunk [repl] (tail call) on line 3, column 1

Thank you.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions