Solved

Freepascal Lnet open multiple sockets

Posted on 2009-04-02
1
1,574 Views
Last Modified: 2013-11-11
I need a bit of help with app. I am using lnet and synaser and trying to open multiple sockets. While I can create the sockets, I can only open the first one called. Any Ideas?
//UNIT1
      begin
           server1 := TTCPEchoDaemon1.Create;
           ServerSer := TServerSerial.Create;
           ServerSer.Execute;
           server1.Run;
      end; 
//EO UNIT1
 
 
//UNIT2
constructor TTCPEchoDaemon2.Create;
begin 
  FCon := TLTCP.Create(nil);
  FCon.OnReceive := @OnRe;
  FCon.Timeout := 100; // responsive enough, but won't hog cpu
  FCon.ReuseAddress := True;
end;
 
Constructor TServerSerial.Create;
begin
  Fser:=TBlockserial.create;
//  FreeOnTerminate:=true;
//  inherited create(false);
end; 
 
procedure TTCPEchoDaemon1.OnRe(aSocket: TLSocket);
var
  s: string;
  n: Integer;
begin
  if aSocket.GetMessage(s) > 0 then begin // if we received anything (result is in s)
//   Writeln('Got: "', s, '" with length: ', Length(s)); // write message and it's length
    RecvString(s); //catch full string
    FCon.IterReset; // now it points to server socket
  end;
end;
 
procedure TTCPEchoDaemon1.Run;
var
  Quit: Boolean; // main loop control
  Port: Word;    // the port to connect to
begin
 
    try
      Port := Word(StrToInt(SysPort1)); // try to parse port from argument
    except
      on e: Exception do begin
        Writeln(e.message);
        Halt;
      end;
    end;
    Quit := false;
 
    if FCon.Listen(Port) then begin // if listen went ok
    Writeln('Server running! on '+SysPort1);
       repeat
        FCon.Callaction; // eventize the lNet
      until Quit; // until user quit
    end; // listen
end; 
 
procedure TServerSerial.Execute;
begin
   with Fser do
    begin
    RaiseExcept:=false;
    Connect(PortNo);
     WriteLn('Serial Port Connected');
     Config(Baud,databits,parity,stopbits ,softwarefl,hardwarefl);
      if active = true then begin
         while not (LastError <> 0) do begin
            if lastError<>0 then break;
              if canread(1000) then  begin
              LCMD := Recvstring(1000);
              WriteLn(LCMD);
              myconverterfunc1:=@CallConv1;
              myconverterfunc1(LCMD);
              end;
         end;
      end;
    end;
end; 
 
function TTCPEchoDaemon1.RecvString(S2: String): AnsiString;
var
  n : integer;
  Stringtest : String;
begin
    n := 1;
    while n <= Length(S2) do begin
          if S2[n] = LF then begin
          myconverterfunc1:=@CallConv1;
          myconverterfunc1(Stringtest);
          stringtest := '';
          Delete(S2, n, 1);
          Continue;
          end;
    Stringtest := Stringtest+Copy(S2, n, 1);
    inc(n);
    end;
 
end;          
 
//EO UNIT2

Open in new window

0
Comment
Question by:lloydie-t
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 

Accepted Solution

by:
lloydie-t earned 0 total points
ID: 24055693
Seems  what I need is Threads.
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
error when doin maven update 2 118
installing and using WTP plugin eclipse MARS 3 138
Eclipse. How to move up/down source folders 4 104
Angular JS Route 3 103
In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Programmer's Notepad is, one of the best free text editing tools available, simply because the developers appear to have second-guessed every weird problem or issue a programmer is likely to run into. One of these problems is selecting and deleti…
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question