Running on windows 10. Installed nim and has been working for some projects. However, I tried to do a simple server using sockets and it's getting an error. See below for full error.
C:UsersusernameDownloadsnimnim-1.6.10bin>nim c --run "c:usersusernamedocumentsnimcodeserver.nim Hint: used config file 'C:UsersusersnameDownloadsnimnim-1.6.10confignim.cfg' [Conf] Hint: used config file 'C:UsersusernameDownloadsnimnim-1.6.10configconfig.nims' [Conf]
c:usersusernamedocumentsnimcodeserver.nim(1, 22) Error: cannot open file: sockets
From what I understand, sockets are a part of the standard library. Here is the code that I tried to compile.
import os, strutils, sockets
let serverAddr = "127.0.0.1" let serverPort = 8080
let serverSocket = newSocket(AF_INET, SOCK_STREAM, 0) serverSocket.bind(serverAddr, serverPort)
serverSocket.listen(1)
let clientSocket = serverSocket.accept()
clientSocket.send("Hello to the client")
clientSocket.close()
Any help on solving this would be highly appreciated. Thanks.
Your using sockets import which is wrong. use import net
You can follow this detailed tutorial for nim sockets:
Try
import os, strutils, net