
30.12.2011, 08:32
|
 |
Let Me Show You
|
|
Регистрация: 30.04.2010
Адрес: Северодвинск
Сообщения: 5,426
Версия Delphi: 7, XE5
Репутация: 59586
|
|
Код:
uses
WinSock,
var
FSocket: TSocket;
const
FTimeOutWrite = 60000;
function send(var Buf; Count: Integer): Integer;
var
ErrorCode: Integer;
FDSet: TFDSet;
TimeVal: TTimeVal;
begin
if FSocket=INVALID_SOCKET then
raise Exception.Create('send: invalid socket');
FD_ZERO(FDSet);
FD_SET(FSocket, FDSet);
TimeVal.tv_sec:=FTimeOutWrite div 1000;
TimeVal.tv_usec:=(FTimeOutWrite mod 1000)*1000;
if select(0, nil, @FDSet, nil, @TimeVal)=SOCKET_ERROR then
raise Exception.Create('send: invalid socket');
if not FD_ISSET(FSocket, FDSet) then
raise Exception.Create('send(): timeout');
Result:=WinSock.send(FSocket, Buf, Count, 0);
if Result=SOCKET_ERROR then
begin
ErrorCode:=WSAGetLastError;
// Close;
raise Exception.Create('send: '+SysErrorMessage(ErrorCode));
end;
end;
procedure Write(s: String);
begin
send(Pointer(s)^, Length(s));
end;
__________________
Пишу программы за еду.
__________________
|