ssl httpserver throwing 'Access violation at address 00000000. Read of address 00000000' error
This code is throwing a 'Access violation at address 00000000. Read of address 00000000' error in runtime. I'm trying to get the server to accept ssl requests but am having real trouble.
I also have ssleay32.dll & libeay32.dll saved in the debug folder. Any help appreciated:
ServerIOHandler := TIdServerIOHandlerSSLOpenSSL.Create; ServerIOHandler.SSLOptions.Method := sslvSSLv23; ServerIOHandler.SSLOptions.Mode := sslmClient; ServerIOHandler.SSLOptions.VerifyMode := ; ServerIOHandler.SSLOptions.VerifyDepth := 0; server:=TIdHTTPServer.Create; server.IOHandler := ServerIOHandler; server.DefaultPort:=port; server.Bindings.DefaultPort:=port; server.OnQuerySSLPort(8092, newBool); //this is the line that throws the error server.AutoStartSession:=true; server.OnCommandGet:=idhttpserver1commandget; server.SessionTimeOut:=360; server.Active:=True;
The reason why you get this error is that OnQuerySSLPort is an event, which you haven't assigned a handler for.
The point of the OnQuerySSLPort is that you should write a method and then assign it to this property of the TIdHTTPServer object. Then this method (that you have written) will be executed everytime the event is fired:
procedure TForm5.MyHandler(APort: TIdPort; var VUseSSL: Boolean); begin // Do something end; procedure TForm5.FormCreate(Sender: TObject); begin server := TIdHTTPServer.Create; server.OnQuerySSLPort := MyHandler; ... end;
You might be more familiary with other events like TForm.OnCreate, TTimer.OnExecute, etc. These work the same way: you write a piece of code that the object then executes when the right time comes.