Open sardaukar opened 7 years ago
Looks like a bug using socket.receive
on TCP connections. However, you probably don't need to use #receive
there. The usual calls are IO#read
and IO#write
. The socket returned by TCPServer#accept
extends the IO module.
iac_will_sga = UInt8.slice(255, 251, 3)
socket.write(iac_will_sga)
puts "IAC WILL SGA sent"
bytes = Slice(UInt8).new(3)
socket.read_fully(bytes)
pp bytes
@RX14 ok, so that works! :D thanks - should I keep the issue open?
Socket#receive
relies on recvfrom(2)
, but apparently we should use recv(2)
for SOCK_STREAM
sockets. Socket#send
works because it calls send(2)
; it calls sendto(2)
when an address is specified only.
I guess we can add support for this. But the behavior of recv
vs recvfrom
is too different (return a message
or a {message, address}
tuple); maybe we should rename receive
to receive_from
and have receive
to return message
only.
In Ruby we have this:
irb(main):014:0> r[1].inspect
=> "#<Addrinfo: empty-sockaddr SOCK_DGRAM>"
but in Crystal an exception is being raised: https://github.com/crystal-lang/crystal/blob/master/src/socket/address.cr#L19-L21 https://github.com/crystal-lang/crystal/blob/master/src/socket/address.cr#L39-L41
Would it be reasonable to have an UNSPECAddress
structure or something like that?
I'm using Crystal v0.21.1 and trying to write a telnet server. A part of the Telnet protocol is to send short binary messages to negotiate features back and forth. Ruby's
net/telnet
features an extensive list.This is my server thus far (reduced code to just have the bug):
The error I get when a client connects on port 2023 is:
What am I doing wrong? I basically want to send a 3 byte message and listen to the client's 3 byte reply.