Tweak sockets.

This commit is contained in:
Brad Nelson
2022-08-12 16:54:50 -07:00
parent b1612c116b
commit 40f45e47e3
4 changed files with 26 additions and 24 deletions

View File

@ -2,34 +2,35 @@
also sockets
also tasks
also posix
1024 constant max-msg
create msg max-msg allot
variable len max-msg len !
-1 value sockfd
variable len max-msg len !
sockaddr incoming
sockaddr outgoing
sockaddr received
variable received-len sizeof(sockaddr_in) received-len !
: reader
begin
sockfd msg len 0 0 0 recvfrom
sockfd msg len 0 received received-len recvfrom
dup 0 >= if
msg swap type cr
received ->addr@ ip. ." :" received ->port@ . space space msg swap type cr
else drop then
pause
again
;
' reader 10 10 task reader-task
sockaddr incoming
sockaddr outgoing
: udp ( port -- )
incoming ->port!
AF_INET SOCK_DGRAM 0 socket to sockfd
sockfd non-block throw
sockfd incoming sizeof(sockaddr_in) bind throw
reader-task start-task
stdin non-block throw
;
: say ( port -- )