Advertisement
Guest User

Untitled

a guest
Sep 15th, 2018
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Nim 0.58 KB | None | 0 0
  1. import asyncdispatch, asyncnet, strutils
  2.  
  3. var socket = newAsyncSocket()
  4.  
  5. proc loop(socket: AsyncSocket) {.async.} =
  6.   while true:
  7.     let client_socket = await socket.accept()
  8.     let size = 40_000_000
  9.     let some_file = repeat("0", size)
  10.     asyncCheck client_socket.send("HTTP/1.1 200 OK\r\nContent-Type: application/zip" &
  11.         "\r\nContent-Length: " & $size &
  12.         "\r\nCache-Control: no-store\r\nConnection: Close\r\n\r\n" & some_file)
  13.     GC_fullCollect() #Using this leads to less memory usage
  14.    
  15. socket.bindAddr(8080.Port)
  16. socket.listen()
  17. waitFor loop(socket)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement