Jump to content
Mark-

TWSocket bind address...

Recommended Posts

Hello,

 

Delphi 10.2.3, (VCL) current version of ICS (V9.4).

 

Testing to verify I caught and handled the issue of the customer entering a bad IP address for binding. The IP address is formatted correctly, just not a valid IP address for any present interface.

I was using the OnError callback. Call connect, onError is called but, "LastError" was zero.

 

Switched to catching it as an exception try Connect except end; LastError is still zero.

 

Looked in the source at

procedure TCustomWSocket.BindSocket;
...
if WSocket_Synchronized_bind(HSocket, PSockAddrIn(@LocalSockName)^, SockNamelen) <> 0 then begin

and the correct error code 10049 (WSAEADDRNOTAVAIL) is present but, it is never assigned to LastError, that I could see.

 

Perhaps there is something different I should be doing.

 

Any ideas?

 

Thanks,

 

Mark

 

Share this post


Link to post
1 hour ago, Mark- said:

I was using the OnError callback. Call connect, onError is called but, "LastError" was zero.

Have you tried calling WSAGetLastError() directly?  At the point where OnError is called, the last socket error code might not have been overwritten yet.

1 hour ago, Mark- said:

Switched to catching it as an exception try Connect except end; LastError is still zero.

The error code is stored in the raised ESocketException in its ErrorCode property.

1 hour ago, Mark- said:

Looked in the source at


procedure TCustomWSocket.BindSocket;
...
if WSocket_Synchronized_bind(HSocket, PSockAddrIn(@LocalSockName)^, SockNamelen) <> 0 then begin

and the correct error code 10049 (WSAEADDRNOTAVAIL) is present but, it is never assigned to LastError, that I could see.

Sounds like a bug that should be reported to the ICS author.

  • Like 1

Share this post


Link to post
22 minutes ago, Remy Lebeau said:

The error code is stored in the raised ESocketException in its ErrorCode property.

Sounds like a bug that should be reported to the ICS author.

Thank you Remy.

 

This: WsocketErrorDesc(ESocketException(exceptObject).ErrorCode) works.

 

image.png.3e584815c58176a47278586e6b90f5ec.png

 

I am hoping Angus reads the post.

Share this post


Link to post
3 hours ago, Mark- said:

This: WsocketErrorDesc(ESocketException(exceptObject).ErrorCode) works.

I don't think you need to call WsocketErrorDesc() as ESocketException also has an ErrorMessage property. 

Share this post


Link to post
6 hours ago, Remy Lebeau said:

I don't think you need to call WsocketErrorDesc() as ESocketException also has an ErrorMessage property. 

You are correct, thank you.

 

Edited by Mark-

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×