Hi Everyone,
Need some guidance here:
I am trying to make a simple SSL server and client using fork. It works properly but I am having problems closing the server socket after the connection. Here is my snippet:
import net
import posix
var pid = fork()
if (pid == 0):
os.sleep(100)
let context = newContext(protVersion = protTLSv1, verifyMode = CVerifyNone)
var socket:Socket = newSocket()
socket.setSockOpt(OptReuseAddr, true)
socket.setSockOpt(OptReusePort, true)
context.wrapSocket(socket)
socket.connect("localhost", Port(4444))
echo "Received from server: " & socket.recvLine()
socket.send("ByeBye\r\n")
context.destroyContext()
socket.close()
else:
var socket:Socket = newSocket()
socket.setSockOpt(OptReuseAddr, true)
socket.setSockOpt(OptReusePort, true)
var context:SslContext = newContext(certFile="mycert.crt", keyFile="mykey.key", verifyMode=CVerifyPeer)
context.wrapSocket(socket)
socket.bindAddr(net.Port(4444))
socket.listen()
var client:Socket = new Socket
socket.accept(client)
echo "client connected"
client.send("Hello\r\n")
echo "Server received: " & client.recvLine()
client.close()
context.destroyContext()
socket.close()
This is the error I am getting: Error: unhandled exception: error:140E0114:SSL routines:SSL_shutdown:uninitialized [SslError]
However, I am unable to add a handler to the socket object as all the fields are not public. Appreciate the help thanks!
However, I am unable to add a handler to the socket object as all the fields are not public. Appreciate the help thanks!
Make them public, see if it helps your case and then we can figure out how to support this in the stdlib properly.
First of all there can be race condition. Client can be executed started before server can be bound.
And to answer your second question, you can easily edit lib/pure/net.nim.
Hi cheatfate
The race shouldnt happen as I did put os.sleep to ensure the server starts before the attempt to connect. This snippet is just an "experiment" for me to play with ssl sockets too.
I will give it a try and then report back about this closing of ssl socket problem