这么简单都没人会??放了2天了~!!不是吧??????????? (5分)

  • 主题发起人 主题发起人 carem1
  • 开始时间 开始时间
C

carem1

Unregistered / Unconfirmed
GUEST, unregistred user!
client端

drivername:string;
selectdriverStream:TStringStream;
begin
selectdriverStream.Create('');
selectdriverStream.write(drivername[1], length(drivername));
ClientSocket1.Socket.SendStream(selectdriverStream);
end;

server端

var
drivername:string;
selectdriverStream:TStringStream;
begin
selectdriverStream.Create('');
////////之后,如何将client发过来的东西放到drivername里面?
end;
 
selectdriverStream.WriteString('sdafasd');
 
to:cash95
什么意思?你这样不是硬将sdafasd写到里面么??
 
TheStream := TWinSocketStream.Create(form1.ClientSocket1.Socket, 20000);
xx := 100;(包长)
TheStream.Write(senddata, blockno);//向服务器发包)
if TheStream.WaitForData(20000) then //定义等待延迟为20秒,
xx := TheStream.read(receiverdata, xx);//从服务器取得的数据
 
先从ServerSocket1读取从客户端发过来的数据后,再加入到SelectDriveStream中就可以了。
 
...AData: TStream;...
sRead: String;
bufRead: array[0..256] of char;
iRead: Integer;
begin
iRead := AData.Read(bufRead,256);
sRead := bufRead;
Setlength(sRead, iRead);
Memo1.Lines.Add(sRead);
 
我是要在server端读取client发送过来的流阿~!!要将他的内容存放在drivername这个字符串里面阿!!!
 
给你答案了!
 
len:=socket.ReceiveLength; LEN
socket.ReceiveBuf(buffer,len); 先收到缓冲
..... 写到目标
 
我的是标准答案,delphi Help里给的
 
to:xusong168 请看看我写的对不对~!!
var
AData: TStream;
drivername,sRead: String;
bufRead: array[0..256] of char;
iRead: Integer;
begin
iRead := AData.Read(bufRead,256);
sRead := bufRead;
Setlength(sRead, iRead);
drivername(sRead);//可不可以这样直接赋值阿?
end;
 
drivername(sRead);不对 drivername :=sRead;
 
如果你用TServerSocket
Non-blocking sockets generate reading and writing events when they need to read or write over the connection. You can respond to these notifications in an OnReceive or OnSend event handler.

The socket object associated with the socket connection is provided as a parameter to the read or write event handlers. This socket object provides a number of methods to allow you to read or write over the connection.

To read from the socket connection, use the ReceiveBuf or Receiveln method. To write to the socket connection, use the SendBuf, SendStream, or Sendln method.
 
请问 3.AData还要先从socket里读取数据 如何操作??
 
var
drivername,sRead: String;
bufRead: array[0..256] of char;
iRead: Integer;
begin
iRead := ServerSocket1.Socket.ReceiveBuf(bufRead,256);
sRead := bufRead;
Setlength(sRead, iRead);
drivername := sRead;
end;
 
var
drivername:string;
begin
drivername := ServerSocket1.Socket.ReceiveText;
end;
 
再麻烦各位兄弟一下,我一运行的时候就会出错,我想是那个drivername的问题~!

client:
ClientSocket1.Socket.SendText('selectdriver');

server:
procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
Socket: TCustomWinSocket);
var
selectdriverStream:TStringStream;
drivername,sRead: String;
bufRead: array[0..256] of char;
iRead: Integer;
begin
if s='selectdriver' then // 选择驱动器并返回
begin
selectdriverStream.Create('');
iRead := selectdriverStream.Read(bufRead,256);
sRead := bufRead;
Setlength(sRead, iRead);
drivername :=sRead;
showmessage(drivername);
end;
end;

 
既然client已经将
ClientSocket1.Socket.SendStream(selectdriverStream);
改成了
ClientSocket1.Socket.SendText('selectdriver');

不妨将server
ServerSocket1.Socket.ReceiveBuf(bufRead,256);
改为
drivername := ServerSocket1.Socket.ReceiveText;

这样匹配,完全没有用到流,少了转换的麻烦
 
ServerSocket1ClientRead这个不对,应该是ServerSocket1ClientWrite
 
因为你的贴子分值少,一般人不会点击的,和里面具体什么问题无关
 
后退
顶部