Guest User

nim async socket server

a guest
Dec 4th, 2022
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. import asyncdispatch, asyncnet
  2.  
  3. proc handleConnection(conn: AsyncSocket) {.async.} =
  4. # Print a message to the console
  5. echo("Received a connection from ", conn.peerAddr)
  6.  
  7. # Close the connection
  8. conn.close()
  9.  
  10. # Open a socket and listen on port 8080
  11. let listener = newAsyncListener(handleConnection, addr = "0.0.0.0"::IPv4, port = 8080)
  12.  
  13. # Print a message to the console
  14. echo("Listening on port 8080...")
  15.  
  16. # Wait for connections to be received
  17. await listener.waitForConnections()
  18.  
Advertisement
Add Comment
Please, Sign In to add comment