Created
October 6, 2011 07:57
-
-
Save mopemope/1266795 to your computer and use it in GitHub Desktop.
EchoServer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import threading/Thread | |
import net/ServerSocket | |
main: func { | |
socket := ServerSocket new("0.0.0.0", 5000) | |
socket listen(100) | |
while(true){ | |
conn := socket accept() | |
Thread new (|| | |
while(true){ | |
buf:Char[256] | |
ret := conn sock receive(buf as Char*, 256, 0) | |
if(!conn sock hasData?){ | |
break | |
} | |
conn sock send(buf as Char*, ret, 0, false) | |
} | |
conn close() | |
) start() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment