关于Socket的一个非常菜的问题!(50分)

  • 主题发起人 主题发起人 shuoshuo
  • 开始时间 开始时间
S

shuoshuo

Unregistered / Unconfirmed
GUEST, unregistred user!
我用ServerSocket控件发送广播!
int i;

for (i=0;i<ServerSocket1->Socket->ActiveConnections;i++)
{
ServerSocket1->Socket->Connections->SendText(Text);
}

为什么老报错!Asynchronous socket error 10054!
 
是否已经有了连到 Server 端的 Client 端了?
 
你使用阻塞方式还是非阻塞方式?
 
已经连接了!非阻塞方式!
 
连接成功否?
 
连接成功了!
错误10054是什麽错误?
 
change servertype to stThreadBlocking
 
是不是在非阻塞方式下不能使用下面的程式?
for (i=0;iSocket->ActiveConnections;i++)
{
ServerSocket1->Socket->Connections->SendText(Text);
}
在非阻塞方式下怎样进行广播试发送?
 
没人理我!我很急的!
 
类似以下:(即发送错误应等下再发,因为cashe满了,参看SendBuf的help)
for (i=0;iSocket->ActiveConnections;i++)
{
while(ServerSocket1->Socket->Connections->SendText(Text)<> 0);
}


 
or 在OnClientWrite中写
procedure TForm1.ServerSocket1ClientWrite(Sender: TObject;
Socket: TCustomWinSocket);
begin
for (i=0;iSocket->ActiveConnections;i++)
{
if ServerSocket1->Socket->Connections=Socket and (Connections未发送) then
begin
Connections已发送
ServerSocket1->Socket->Connections->SendText(Text);
end;
}
end;
 
10054: 远程主机强迫关闭了一个现有的连接。
 
qpx:请问如何能知道cashe满了!
 
when SendBuf returns -1 then cashe满了!
please see the help text of function SendBuf as follow:

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.
 
多人接受答案了。
 
后退
顶部