Lnet dual communication? lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- Jake012345 · 2020-04-10 15:21 (sorry I'm bad in english and new in here, so may I'm stupid and avoid the answer in other posts) Hello! I want to write a program what can communicate with other running. But I cant figure out how can I send two Integer data with one TcpComponent. In the program, we have two shapes and we can control the green with mouse. In the other window we can control the other shape.(we can see it as green). So they send them Shape1.coordinate to the other and it set to the Shape2.Coor. How? The datas always shaking or just one of them arrive. ;( ---------------------------------------------------------------------- Handoko · 2020-04-10 15:39 Hello Jake012345, Welcome to the forum. I'm not very proficient in network programming. But I remember there was a demo program similar to what you said. https://wiki.freepascal.org/Portal:HowTo_Demos The demo is in the link above, in Networking section > Game Client and Server. ---------------------------------------------------------------------- Jake012345 · 2020-04-10 16:24 Sorry, It's very useful in the future , but at the moment I'm a beginner of programming . Now enough for me a trick to compress the two integer to string and turn back on the other side. (sure i must know which is wich) Maybe run more sockets and send messages on it. (if more than one socket can connect to client) ---------------------------------------------------------------------- af0815 · 2020-04-10 17:25 look for IntToStr this is the function to convert a integer to string. ---------------------------------------------------------------------- howardpc · 2020-04-10 18:08 You can make little helper routines for converting coordinates to a string and back, such as Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i uses SysUtils, Types; function PointToString(aPoint: TPoint; aSeparator: Char): String;begin  Result := Format('%d%s%d', [aPoint.X, aSeparator, aPoint.Y]);end; function StringToPointOK(const aString: String; out Point: TPoint;  aSeparator: Char): Boolean;var  p: SizeInt;begin  Point := Default(TPoint);  p := Pos(aSeparator, aString);  Result := (Length(aString) > 2) and (p > 1);  if Result then    Result := TryStrToInt(Copy(aString, 1, p-1), Point.X) and              TryStrToInt(Copy(aString, p+1, MaxInt), Point.Y);end; ---------------------------------------------------------------------- Jake012345 · 2020-04-10 18:12 I know but i dont know how can i use it... messagout:=('x'+IntToStr(cursor.x)+'y'+IntToStr(cursor.y)); sendmessage(messageout,socket); AND getmessage(messagein,socket); and here? For example I have it now: 'x124y33' How can i cut '124' to use the StrToInt and cut the '33' while I know what number is which? ---------------------------------------------------------------------- Jake012345 · 2020-04-10 18:15 thanks! I'm trying it out! ---------------------------------------------------------------------- howardpc · 2020-04-10 18:19 Code: [Select]sendmessage(PointToString(shape1.BoundsRect.TopLeft), socket); ...var s: String;  pt: TPoint; ... getmessage(s, socket); if StringToPointOK(s, pt) then begin   Shape2.Top := pt.Y;    Shape2.Left := pt.X; end; ---------------------------------------------------------------------- Jake012345 · 2020-04-11 08:12 Thank you! But my code is probably wrong... The StrToPoint working but the shape2 don't move. Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i unit Unit1; {$mode objfpc}{$H+} interface uses  Classes, SysUtils, Forms, Controls, Graphics, Dialogs, StdCtrls, ExtCtrls,  lNetComponents, lNet, Types; type   { TForm1 }   TForm1 = class(TForm)    Button1: TButton;    Button2: TButton;    Edit1: TEdit;    Label1: TLabel;    Label2: TLabel;    LTCPComponent1: TLTCPComponent;    Shape1: TShape;    Shape2: TShape;    Timer1: TTimer;    procedure Button1Click(Sender: TObject);    procedure Button2Click(Sender: TObject);    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;      Shift: TShiftState; X, Y: Integer);    procedure LTCPComponent1Accept(aSocket: TLSocket);    procedure LTCPComponent1Connect(aSocket: TLSocket);    procedure LTCPComponent1Receive(aSocket: TLSocket);    procedure Timer1Timer(Sender: TObject);  private   public   end; var  Form1: TForm1; implementation {$R *.lfm} { TForm1 }   var s:string;       started:boolean;       x,y:TLSocket;       buffer:TLSocket;       ptout:Tpoint;       ptin:TPoint;       p:TPoint;       messagein:String;  function PointToString(aPoint: TPoint; aSeparator: Char): String;beginResult := Format('%d%s%d', [aPoint.X, aSeparator, aPoint.Y]);end; function StringToPointOK(const aString: String; out Point: TPoint;  aSeparator: Char): Boolean;  var p: SizeInt;begin   Point := Default(TPoint);   p := Pos(aSeparator, aString);   Result := (Length(aString) > 2) and (p > 1);   if Result then     Result := TryStrToInt(Copy(aString, 1, p-1), Point.X) and     TryStrToInt(Copy(aString, p+1, MaxInt), Point.Y);end; procedure TForm1.LTCPComponent1Accept(aSocket: TLSocket);begin  LTCPComponent1.SendMessage('start',buffer);  end; procedure TForm1.LTCPComponent1Connect(aSocket: TLSocket);begin  LTCPComponent1.SendMessage('start',buffer);end; procedure TForm1.LTCPComponent1Receive(aSocket: TLSocket);begin  LTCPComponent1.GetMessage(s,buffer);  if s='start' then started:=true; if started=true then begin   LTCPComponent1.GetMessage(messagein,x);  end; end; procedure TForm1.Timer1Timer(Sender: TObject);begin  if started=true then begin   Form1.Shape1.Left:=(p.x)-(Shape1.Width div 2);  Form1.Shape1.Top:=(p.y)-(Shape1.Height div 2);   ptout.x:=Shape1.Left;  ptout.y:=SHape1.Top;  LTCPComponent1.sendmessage(PointToString(ptout,'-'),x);   if StringToPointOK(messagein,ptin,'-') thenbegin  Shape2.Top := ptin.Y;   Shape2.Left := ptin.X;end;   end;end; procedure TForm1.Button1Click(Sender: TObject);begin  LTCPComponent1.Host:=Edit1.Text;  LTCPComponent1.Listen(22,'sad');end; procedure TForm1.Button2Click(Sender: TObject);begin  LTCPComponent1.Connect(Edit1.Text,22);end; procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;  Shift: TShiftState; X, Y: Integer);begin  p:=ScreenToClient(Mouse.CursorPos);end; end. ---------------------------------------------------------------------- Jake012345 · 2020-04-11 08:37 And I have an other question: Can I make more connection between two programs with one component? (Just because I plan to write a little bit more comlicated program with lots of data types)