W
W
WizAlx2013-03-02 13:57:53
Delphi
WizAlx, 2013-03-02 13:57:53

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>


Server part:
<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>


I will note in advance that the port of ClientSocket and ServerSocket is the same.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
Hint, 2013-03-02
@WizAlx

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 question

Ask a Question

731 491 924 answers to any question