如何使用tsocket的sendbuf和receivebuf(100分)

  • 主题发起人 主题发起人 g622
  • 开始时间 开始时间
G

g622

Unregistered / Unconfirmed
GUEST, unregistred user!
如何使用tsocket的sendbuf和receivebuf接受和发送二进制文件,
最好给个例子.
 
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. 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, SendBuf may write from a socket that is expected to write to the connection without a notification to signal the connection抯 readiness to read. 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.

Reads up to Count bytes from the socket connection into the Buf parameter.

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

Description

Use ReceiveBuf to read from the socket connection in the OnSocketEvent event handler of a Windows socket object or in the OnRead or OnClientRead event handler of a socket component. ReceiveBuf returns the number of bytes actually read.

ReceiveBuf only works in response to a read notification to a non-blocking windows socket. Blocking sockets must use a TWinSocketStream for reading. The TWinSocketStream object waits for the remote socket to be ready before transferring information.

Note: While the ReceiveLength method can return an estimate of the size of buffer required to retrieve information from the socket, the number of bytes it returns is not necessarily accurate.

Delphi中有例子. 好像是 Chat 的例子.
 
C:/Program Files/Borland/Delphi5/Demos/Internet/Chat
 
:)
谢谢!
but.......
chat中使用的是sendtext 和 receivetext
我要送出的是二进制数据.....

 
Socket.SendStream
 
把二进制数据读到pchar里面,然后:

发送:
clientsocket1.socket.SendBuf(cf1^,count);

读取:
count:=socket.ReceiveLength;
getmem(cf1,count);
socket.ReceiveBuf(cf1^,count);

上面的cf1是pchar类型.

 
多人接受答案了。
 
后退
顶部