Tweak sockets.
This commit is contained in:
@ -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 -- )
|
||||
|
||||
Reference in New Issue
Block a user