0

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.

Yordan Yanakiev
  • 2,546
  • 3
  • 39
  • 88
  • 2
    `TClientSocket` and `TServerSocket` 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 from `TCustomWinSocket.SendText()` and `TCustomWinSocket.ReceiveText()` in Delphi 2009+, as they were never updated to handle `UnicodeString` correctly. Use `TCustomWinSocket.SendBuffer()` and `TCustomWinSocket.ReceiveBuffer()` instead. – Remy Lebeau May 23 '22 at 04:00
  • 2
    More importantly, you didn't say whether you are using the `Socket` in thread-blocking mode or not. Please provide a [mcve]. If you are using thread-blocking mode, you should be using `TWinSocketStream` for socket I/O, where you should use `TWinSocketStream.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. – Remy Lebeau May 23 '22 at 04:00
  • Didn't know any of that. Probably missed it. Yet, by some reason I don't see any of these functions available here by some reason.. :| – Yordan Yanakiev May 23 '22 at 05:55

0 Answers0