Hola,
Probando el archivo adjunto de mi último mensaje el ejemplo no parece funcionar bien, al menos aquí en Windows 10. Sin embargo, probando el programa en que estoy usando "Sockets" y que originó este hilo sí que puedo enviar y recibir cadenas de un cliente a un servidor y viceversa. Lo cierto es que ahora mismo on sabría bien qué responderte. Quizá el código de abajo, usado en mi programa, te dé una idea y te sirva de algo:
Código Delphi
[-]
unit USocketsCommom;
interface
uses
ScktComp;
procedure SendStringToSocket( Socket:
TCustomWinSocket; Buffer: string );
implementation
uses
Forms, SysUtils, Classes, WinSock;
procedure SendMemoryStreamToSocket( socket :
TCustomWinSocket; buffer : TMemoryStream);
var
dataPtr: PByte;
numSent: integer;
begin
buffer.Position := 0;
dataPtr := PByte( buffer.Memory );
while buffer.Position < buffer.Size do
begin
numSent := socket.SendBuf
(
dataPtr^,
buffer.Size - buffer.Position
);
if numSent < 0 then
begin
if WSAGetLastError() = WSAEWOULDBLOCK then
begin
Sleep( 50 );
Continue;
end;
Exit;
end;
if numSent = 0 then
begin
Exit; end;
Inc(dataPtr, numSent);
buffer.Seek(numSent, soFromCurrent);
Application.ProcessMessages();
end;
end;
procedure SendStringToSocket( socket:
TCustomWinSocket; buffer: string );
var
ms : TMemoryStream;
begin
ms := TMemoryStream.Create();
try
ms.WriteBuffer( Pointer( buffer )^, Length( buffer ) );
SendMemoryStreamToSocket( socket, ms );
finally
ms.Free();
end;
end;
end.
Ese es el código que uso en mi programa para enviar cadenas en ambos cliente y servidor. Dicho código parece el resumen de este hilo, en el sentido de que es el que al final estoy usando en mi programa, y, como digo, este funciona como se espera incluso aquí en Windows 10.