Forum > Networking and Web Programming

Server with TBlockSocket

(1/2) > >>

michoux:
Hello,
I have found some simple code in forum to start a simple server


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---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;             

paweld:
nxPascal ( https://github.com/Zaflis/nxpascal ) - demo: https://github.com/Zaflis/nxpascal/tree/master/demos/fpc/networkTest
or demo shared by @GetMem: https://forum.lazarus.freepascal.org/index.php/topic,48677.msg350793.html#msg350793

michoux:
nxPascal  is nice, but I can not connect to it from custom client, allways get timeout

<#1 Error(10060): Connection timed out>
<#1: Socket closed>


I did a simple test with telnet to pport

paweld:
clear Mask:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---server.Mask := '';

michoux:
Hmm
Still the same

<#2: Opened new socket>
<#2 Error(10060): Connection timed out>
<#2: Socket closed>

Navigation

[0] Message Index

[#] Next page

Go to full version