I have a thread where I am opening a socket, and executing it, waiting to receive strings from the other side. It is working fine compiled on Delphi 7 on all Windows version, yet compiled with Delphi 11 - it working on the rest of the Windows versions, except 11. Under Windows 11 I am getting the Socket.ReceiveText to be empty and Socket.ReceiveLength to be always 0.
TThread_Connection_Main = class( TThread )
Socket: TCustomWinSocket;
constructor Create(aSocket: TCustomWinSocket); overload;
procedure Execute; override;
end;
procedure TThread_Connection_Main.Execute;
begin
inherited
while Socket.Connected do
begin
Sleep( 2);
if ( Socket = nil ) or not( Socket.Connected ) then
Break;
if Socket.ReceiveLength < 1 then
Continue;
...
end;
end;
- Is there something specific which have to be done for Windows 11 sockets compatibility with Delphi 11 ?
P.S: Just found out that the issue exists with Delphi 10.4 as well.
TClientSocket
andTServerSocket
have changed very little over the years, and the base Winsock API hasn't changed. So, whatever worked in old versions should still work in newer versions. Except, you should stay away fromTCustomWinSocket.SendText()
andTCustomWinSocket.ReceiveText()
in Delphi 2009+, as they were never updated to handleUnicodeString
correctly. UseTCustomWinSocket.SendBuffer()
andTCustomWinSocket.ReceiveBuffer()
instead.Socket
in thread-blocking mode or not. Please provide a minimal reproducible example. If you are using thread-blocking mode, you should be usingTWinSocketStream
for socket I/O, where you should useTWinSocketStream.WaitForData()
before reading bytes. Otherwise, if you are not using thread-blocking mode, then your thread is missing a message loop to process and dispatch internal socket notifications.