sendbufer的使用问题 (100分)

  • 主题发起人 主题发起人 waterflow
  • 开始时间 开始时间
W

waterflow

Unregistered / Unconfirmed
GUEST, unregistred user!
我在使用clientsocket进行通信时碰到一些问题:
程序要实现的功能要求:
1:有消息立即发送出去(到广域网对方)
2:发送完后处于读取对方返回信息状态并进行处理

当设置clientsocket的clienttype为ctblocking时,使用线程来发送信息
信息可以立即发送出去,但是读取对方信息有问题(我实在onread事件中读取信息)
onread事件根本不发生,同时我把程序关闭,对方却还有连结存在(这样导致几次后就到达
对方连结次数的上限)
当设置clientsocket的clienttype为ctNonblocking时,直接利用sendbuf来发送,但是
却不能立即发送,文档上说该函数只是向winsock dll发送消息,但是onread立即发生,且
能接受信息,当我把程序关闭后,好像是发送很多次后,经过10多分钟,所有的消息批量
发送出去,是不是在winsock dll中设置了包的大小,只有到一定程度后才真正发送,如何
解决
还是我根本就用错了空间
 
Writes Count bytes to the socket connection from the Buf parameter.

function SendBuf(var Buf; Count: Integer): Integer;

Description

Use SendBuf to write to the socket connection. Call this method from the OnSocketEvent
event handler of a Windows socket object or in the OnWrite or OnClientWrite event
handler of a socket component. Alternately, Use SendBuf to write when a connection
is first formed when the socket does not expect notification that the socket on the
other end of the connection is expecting to read.

For non-blocking sockets, the data is sent to the WinSock DLL which has it's own
internal buffers. If the WinSock can accept additional data, SendBuf returns
immediately with the number of bytes queued. If the WinSock internal buffer space
is not able to accept the buffer being sent, SendBuf returns -1 and no data is
queued at all. In this case, wait a bit for the WinSock to have a chance to send
out already-queued data; then try again.

For blocking sockets, SendBuf returns the number of bytes actually written.

If an error occurs while writing to the connection, SendBuf terminates the
connection and raises an ESocketError exception.

看看真正发了多少个出去!!!
 
to honestman
没有一个字节发送出去
 
多人接受答案了。
 
后退
顶部