Hello,
I have found some simple code in forum to start a simple server
procedure TForm1.Button3Click(Sender: TObject);
begin
listenersocket1:=TBlockSocket.Create;
listenersocket1.CreateSocket;
listenersocket1.Bind('127.0.0.1'7000);
listenersocket1.Listen;
repeat
Application.ProcessMessages;
if listenersocket1.CanRead(10) then begin
connection1:=TBlockSocket.Create;
connection1.Socket:=listenersocket1.Accept;
connected1:=true;
end;
until false;
end;
All ok, now I have problems because I want to connect 2 clients to this server, which is impossible
Is there any simple example with threads? I am not really familiar with threads in lazarus ....
I found a workaround to create 2 servers each client would connect to own server, if some message received on server A I can pass it to server B with connection.SendString(message+CR+LF);
But somehow if both servers are working and client disconnects it can not get back any more to server.
procedure TForm1.Button3Click(Sender: TObject);
begin
listenersocket1:=TBlockSocket.Create;
listenersocket1.CreateSocket;
listenersocket1.Bind('127.0.0.1',7000);
listenersocket1.Listen;
repeat
Application.ProcessMessages;
if listenersocket1.CanRead(10) then begin
connection1:=TBlockSocket.Create;
connection1.Socket:=listenersocket1.Accept;
connected1:=true;
end;
until false;
end;
procedure TForm1.Button4Click(Sender: TObject);
begin
listenersocket:=TBlockSocket.Create;
listenersocket.CreateSocket;
listenersocket.Bind('127.0.0.1',7001);
listenersocket.Listen;
repeat
Application.ProcessMessages;
if listenersocket.CanRead(10) then begin
connection:=TBlockSocket.Create;
connection.Socket:=listenersocket.Accept;
connected:=true;
end;
until false;
end;
procedure TForm1.Timer1Timer(Sender: TObject);
begin
Application.ProcessMessages;
if connected=true then begin
commessage:=connection.RecvString(10);
if mmessage<>'' then begin
connection1.SendString(mmessage+CR+LF);
end;
end;
end;