Главная страница
    Top.Mail.Ru    Яндекс.Метрика
Форум: "Сети";
Текущий архив: 2004.08.01;
Скачать: [xml.tar.bz2];

Вниз

Так что же означает результат, возвращаемый SendText() ?   Найти похожие ветки 

 
VID ©   (2004-06-03 21:31) [0]

Сразу хочу отметить что у меня Delphi 5. В хелпе (D5), для TCustomWinSocket.SendText() читаю:

Writes the string S to the socket connection.

function SendText(const S: string): Integer;

Description

Use SendText to write a string to the socket connection. The writing may occur in the OnSocketEvent event handler of a Windows socket object or in the OnWrite or OnClientWrite event handler of a socket component. Alternately, SendText may write from a socket that is expected to write to the connection without a notification to signal the connection’s readiness to read. If an error occurs while writing to the connection, SendText terminates the connection and raises an ESocketError exception.

SendText returns 0 if the string was successfully written. It returns a nonzero value if the writing must be postponed. When SendText returns a nonzero value, it must be called again later to write the value over the connection.


Судя по том, что выделено жирным, получается что если SendText вернёт 0, то я должен повторить отправку текста позже. Вроде бы всё неплохо, но вот что пишется в хелпе от Delphi 6 по этому поводу:

Writes the string S to the socket connection.

function SendText(const S: string): Integer;

Description

Use SendText to write a string to the socket connection. The writing may occur in the OnSocketEvent event handler of a Windows socket object or in the OnWrite or OnClientWrite event handler of a socket component. Alternately, SendText may write from a socket that is expected to write to the connection without a notification to signal the connection’s readiness to read. If an error occurs while writing to the connection, SendText terminates the connection and raises an ESocketError exception.

SendText returns the number of bytes sent. Note that this may be less than the length of the string S if the socket is nonblocking.


Здесь уже пишется что SendText() возвращает число отправленый байтов. И ещё то, что это число может быть меньше, чем длина строки, в случае если используются неблок. сокеты.

У меня сервер работает в режиме stNonBlocking.
Возникает вопрос: если функция SendText() у меня вернёт >0 то что мне делать: отправить ВЕСЬ текст заново, или только остаток, взависимости от того, какое число вернуло SendText() ?

Вот реализация SendText

function TCustomWinSocket.SendText(const s: string): Integer;
begin
 Result := SendBuf(Pointer(S)^, Length(S));
end;

function TCustomWinSocket.SendBuf(var Buf; Count: Integer): Integer;
var
 ErrorCode: Integer;
begin
 Lock;
 try
   Result := 0;
   if not FConnected then Exit;
   Result := send(FSocket, Buf, Count, 0);
   if Result = SOCKET_ERROR then
   begin
     ErrorCode := WSAGetLastError;
     if (ErrorCode <> WSAEWOULDBLOCK) then
     begin
       Error(Self, eeSend, ErrorCode);
       Disconnect(FSocket);
       if ErrorCode <> 0 then
         raise ESocketError.CreateResFmt(@sWindowsSocketError,
           [SysErrorMessage(ErrorCode), ErrorCode, "send"]);
     end;
   end;
 finally
   Unlock;
 end;
end;



Как видно из кода SendBuf, для отправки данных используется
Result := send(FSocket, Buf, Count, 0);
А это WinAPI функция и я думаю на всех Windows она реализована одинаково, в независимости от того какая Delphi установлена.

В-общем весь вопрос сводится к одному:
В случае возврата функцие SendText() >0 отправлять текст заново ВЕСЬ целиком, или только неотправленную часть ?

D5.WinXP.


 
VID ©   (2004-06-03 21:33) [1]

>>Судя по том, что выделено жирным, получается что если SendText вернёт 0

Имелось ввиду
"Судя по том, что выделено жирным, получается что если SendText вернёт не 0"


 
Digitman ©   (2004-06-04 08:18) [2]


> В случае возврата функцие SendText() >0 отправлять текст
> заново ВЕСЬ целиком, или только неотправленную часть ?


только не отправленную


 
VID ©   (2004-06-04 12:11) [3]

Я так и сделал. Работает.
Но что я заметил: у меня функция SendText всегда возвращает длину отправленного текста. Т.е. если текст был 10 символов, то вызов SendText вернёт 10 ! А ведь должен вернуть 0 судя по хелпу Delphi 5 ! Получается что верить надо хелпу Delphi 6...



Страницы: 1 вся ветка

Форум: "Сети";
Текущий архив: 2004.08.01;
Скачать: [xml.tar.bz2];

Наверх





Память: 0.46 MB
Время: 0.037 c
14-1089573298
DcSoft for Clie
2004-07-11 23:14
2004.08.01
Программирование на Delphi для PALM


14-1089704267
Max Ivanych
2004-07-13 11:37
2004.08.01
Всю ночь снился Access...


9-1082796215
Комбинатор
2004-04-24 12:43
2004.08.01
Проблема с туманом...


1-1090013736
НовичОк
2004-07-17 01:35
2004.08.01
Как сделать так чтобы прога выглядела по XP шному?


3-1089202599
Zhekson
2004-07-07 16:16
2004.08.01
как при помощи визуальных компон. формировать код SQL?





Afrikaans Albanian Arabic Armenian Azerbaijani Basque Belarusian Bulgarian Catalan Chinese (Simplified) Chinese (Traditional) Croatian Czech Danish Dutch English Estonian Filipino Finnish French
Galician Georgian German Greek Haitian Creole Hebrew Hindi Hungarian Icelandic Indonesian Irish Italian Japanese Korean Latvian Lithuanian Macedonian Malay Maltese Norwegian
Persian Polish Portuguese Romanian Russian Serbian Slovak Slovenian Spanish Swahili Swedish Thai Turkish Ukrainian Urdu Vietnamese Welsh Yiddish Bengali Bosnian
Cebuano Esperanto Gujarati Hausa Hmong Igbo Javanese Kannada Khmer Lao Latin Maori Marathi Mongolian Nepali Punjabi Somali Tamil Telugu Yoruba
Zulu
Английский Французский Немецкий Итальянский Португальский Русский Испанский