mirror of
				https://github.com/janet-lang/janet
				synced 2025-10-26 05:07:41 +00:00 
			
		
		
		
	 f4a46ba6ea
			
		
	
	f4a46ba6ea
	
	
	
		
			
			This makes streams polymorphic with files in many cases. printf family functions still need porting.
		
			
				
	
	
		
			14 lines
		
	
	
		
			308 B
		
	
	
	
		
			Janet
		
	
	
	
	
	
			
		
		
	
	
			14 lines
		
	
	
		
			308 B
		
	
	
	
		
			Janet
		
	
	
	
	
	
| (defn handler
 | |
|   "Simple handler for connections."
 | |
|   [stream]
 | |
|   (defer (:close stream)
 | |
|     (def id (gensym))
 | |
|     (def b @"")
 | |
|     (print "Connection " id "!")
 | |
|     (while (:read stream 1024 b)
 | |
|       (:write stream b)
 | |
|       (buffer/clear b))
 | |
|     (printf "Done %v!" id)))
 | |
| 
 | |
| (net/server "127.0.0.1" "8000" handler)
 |