Answer the question
In order to leave comments, you need to log in
Pass array via Socket?
Dear Khabrchane. The question is the following.
You need to pass an array of data from ClientSocket to ServerSocket. The code below, unfortunately, does not work, the array is not passed. Please help me correct the errors.
Client side:
procedure TForm1.IPBtnClick(Sender: TObject);<br>
begin<br>
Client.Host:=Ip.Text;<br>
Client.Address:=Ip.Text;<br>
Client.Active:=true;<br>
Buf[1]:=IdIPWatch1.CurrentIP;<br>
Buf[2]:=IdIPWatch1.UnitName;<br>
Client.Socket.SendBuf(Buf,SizeOf(Buf));<br>
end;<br>
<br>
procedure TForm1.ServerClientRead(Sender: TObject;<br>
Socket: TCustomWinSocket);<br>
begin<br>
server.Socket.ReceiveBuf(Buf,SizeOf(Buf));<br>
Tree.Items.AddChild(TreeView1.Items.Item[0],Buf[1]) <br>
end;<br>
Answer the question
In order to leave comments, you need to log in
You're doing it wrong. The data sent over a socket is a stream of data without end or beginning (not counting the establishment and closing of the connection). Accordingly, the client and the server must somehow determine that one line ended here, and another began here. You can determine by zero bytes or send lines of a fixed size. And you can come up with your protocol. Here I don't see it.
What is buff? array of string?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question