请问如何用socket制作多个client同时发送文件到一个server端,是否一定要用线程?有没有相关的例子啊?大富翁只有点对点的例子(10分)

  • 主题发起人 主题发起人 msc
  • 开始时间 开始时间
M

msc

Unregistered / Unconfirmed
GUEST, unregistred user!
请问如何用socket制作多个client同时发送文件到一个server端,是否一定要用线程?有没有相关的例子啊?大富翁只有点对点的例子
 
The following example shows a typical ClientExecute method for a custom descendant of TServerClientThread. It reads from the socket connection specified by ClientSocket using a thread-local instance of TWinSocketStream.

procedure TMyServerThread.ClientExecute;

var
Stream : TWinSocketStream;
Buffer : array[0 .. 9] of Char;
begin
{ make sure connection is active }
while (not Terminated) and ClientSocket.Connected do
begin
try
Stream := TWinSocketStream.Create(ClientSocket, 60000);
try
FillChar(Buffer, 10, 0); { initialize the buffer }
{ give the client 60 seconds to start writing }
if Stream.WaitForData(60000) then

begin
if Stream.Read(Buffer, 10) = 0 then { if can抰 read in 60 seconds }
ClientSocket.Close; { close the connection }
{ now process the request }
...
end
else
ClientSocket.Close; { if client doesn抰 start, close }
finally
Stream.Free;
end;
except
HandleException;

end;
end;
end;
 
delphi自己的help!!
 
10分啊???(打个75折,刚刚够下面的分数)
SERVERSOCKET端用阻塞线程模式;
CLIENTSOCKET端用非阻塞模式。
 
delphi的help?在哪里?我没有分了,请帮忙
 
delphi的help好像没有说socket的线程模式
 
首先先分清楚你用什么写如果是DELPHI完全不用线程的概念,如果是JAVA不用线程肯定不行!
如果是DELPHI那么建议你使用ICS的控件包!其中的SOCKETSERVER/SOCKET非常好用而且有例子!
 
后退
顶部