Recent

Author Topic: TLTCP components problem  (Read 18774 times)

zdenal027

  • Newbie
  • Posts: 6
TLTCP components problem
« on: April 14, 2011, 04:47:43 pm »
Hello,

I'm trying to write program which use two TLTCP components - I need to connect to two servers with different ports. When enable only one TLTCP component (comment out TCP*.Connect(...) of second one), it behaves well. But when both are enabled, program hangs after while (about 5 seconds, so some packets are received and send). Simplified code inserted below. BTW, in the listbox I can see "connecting...", "connected", but "connection accepted" never appears... Is is ok? Thanks for any help!

Best regards,
Zdenek Materna

Code: [Select]
procedure TMainForm.ConnectClick(Sender: TObject);
begin
  Stream1.SetSize(0);
  StatusBar.SimpleText := 'connecting...';
  ListBox1.Items.Add('connecting...');
  TCPSock.Connect(Host.Text, Port.Value);
  TCPcom.Connect(Host.Text, Port1.Value);
end;

procedure TMainForm.TCPcomAccept(aSocket: TLSocket);
begin
   ListBox1.Items.Add('TCPcom: connection accepted on server');
end;

procedure TMainForm.TCPcomConnect(aSocket: TLSocket);
begin
   ListBox1.Items.Add('TCPcom connected');
end;

procedure TMainForm.Button1Click(Sender: TObject);
var
  mes : AnsiString;
begin

  mes := ...
  ListBox1.Items.Add('sending : ' + mes);
  TCPcom.SendMessage(mes);
end;

procedure TMainForm.TCPcomDisconnect(aSocket: TLSocket);
begin
ListBox1.Items.Add('TCPcom: disconnect');
end;

procedure TMainForm.TCPcomError(const msg: string; aSocket: TLSocket);
begin
  ListBox1.Items.Add('TCPcomError: ' + msg);
end;

procedure TMainForm.TCPcomReceive(aSocket: TLSocket);
var
buff: string;
recv: integer;
hor: integer;
vert: integer;
begin

     recv :=  aSocket.GetMessage(buff);

   ListBox1.Items.Add('received ' + IntToStr(recv) + ' bytes: ' + buff);

  SScanf(buff,'[PH:%d PV:%d]',[@hor,@vert]);

  vertSkutPoz.Position:=vert;
  horSkutPoz.Position:=hor;

end;

procedure TMainForm.TCPSock1Accept(aSocket: TLSocket);
begin
ListBox1.Items.Add('TCPSock: connection accepted on server');
end;

procedure TMainForm.TCPSockAccept(aSocket: TLSocket);
begin
ListBox1.Items.Add('TCPSock: connection accepted on server');

end;

procedure TMainForm.TCPSockConnect(aSocket: TLSocket);
begin
  StatusBar.SimpleText := 'sending request...';
  aSocket.SendMessage('GET /?action=stream' + #10+ #10);
end;

procedure TMainForm.TCPSockDisconnect(aSocket: TLSocket);
begin
ListBox1.Items.Add('TCPSock: disconnect');

end;

procedure TMainForm.TCPSockError(const msg: string; aSocket: TLSocket);
begin
  StatusBar.SimpleText := 'connect failed';
  ListBox1.Items.Add('TCPSock error: ' + msg);
end;


procedure TMainForm.TCPSockReceive(aSocket: TLSocket);
var
  res, i, j : Integer;
begin
  res := aSocket.Get( buffer[0], sizeof(buffer) );
  if res = 0 then exit;
  .....
 ......
 .....
end;   

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: TLTCP components problem
« Reply #1 on: April 14, 2011, 06:36:14 pm »
OnAccept events are server-side not client side (TLTcpComponent can be both a client and a server, depends on if you use .Connect or .Listen).

So you will never see the Accept event if you're connecting.

I'm not sure why it hangs for you, if you comment the other connection out, it works.. for both? (e.g: you uncomment one and then the other and it always works this way).

Btw. are you Czech?

zdenal027

  • Newbie
  • Posts: 6
Re: TLTCP components problem
« Reply #2 on: April 15, 2011, 09:18:23 am »
Thanks for explanation.

Exactly - when I comment out one, second runs ok. For both. I don't know if "hang" is right description - it seems that program lives - gui isn't responding, but when I click on button which sends TCP paket, paket is received on server... Strange.

Yes, I'm Czech :-)

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: TLTCP components problem
« Reply #3 on: April 15, 2011, 10:20:55 am »
Tak to zdar :)

No neviem co je presne problem, ak mozes posli mi celu aplikaciu (zdrojaky len) ja to skusim na echo serveri, bude to len nejaka somarina.

zdenal027

  • Newbie
  • Posts: 6
Re: TLTCP components problem
« Reply #4 on: April 15, 2011, 10:31:56 am »
Zdravím :D

Nejde o nic tajnýho, tak jsme to hodil na leteckou poštu: http://leteckaposta.cz/129955109

Dík moc. Taky si myslím, že to bude nějaká chujovina.

JD

  • Hero Member
  • *****
  • Posts: 1849
Re: TLTCP components problem
« Reply #5 on: April 15, 2011, 12:49:10 pm »
@Almindor2
Are you the same Almindor that wrote a 2D game in FreePascal a while back?
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: TLTCP components problem
« Reply #6 on: April 15, 2011, 09:10:54 pm »
@zdenal: Pozrem a uvidim :) Zajtra by som na to mal mat cast

@Almindor2
Are you the same Almindor that wrote a 2D game in FreePascal a while back?

Yep, that's me, I lost my old "Almindor" login with my old ISP's email I had.

Jishaxe

  • Full Member
  • ***
  • Posts: 103
  • Hobbist Programmer
Re: TLTCP components problem
« Reply #7 on: April 15, 2011, 11:29:42 pm »
@zdenal: Pozrem a uvidim :) Zajtra by som na to mal mat cast

@Almindor2
Are you the same Almindor that wrote a 2D game in FreePascal a while back?

Yep, that's me, I lost my old "Almindor" login with my old ISP's email I had.
A cooler name would have been "AlmindorTheSecond" or "UltraAlmindor" :P
Wait, can't you just change your forum nickname to Almindor? Mine used to be Joshuzzz but now it's Jishaxe 'cause I changed it?
Linux Mint 12
Windows 7 Home Premium
______________________
Definition of programmer: An organism that converts caffeine into software.

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: TLTCP components problem
« Reply #8 on: April 16, 2011, 12:11:26 am »
A cooler name would have been "AlmindorTheSecond" or "UltraAlmindor" :P
Wait, can't you just change your forum nickname to Almindor? Mine used to be Joshuzzz but now it's Jishaxe 'cause I changed it?

Yeah you're right :)

I didn't realize it can be changed from the login name.

Jishaxe

  • Full Member
  • ***
  • Posts: 103
  • Hobbist Programmer
Re: TLTCP components problem
« Reply #9 on: April 16, 2011, 12:13:56 am »
^^
Linux Mint 12
Windows 7 Home Premium
______________________
Definition of programmer: An organism that converts caffeine into software.

JD

  • Hero Member
  • *****
  • Posts: 1849
Re: TLTCP components problem
« Reply #10 on: April 16, 2011, 11:04:38 am »
@zdenal: Pozrem a uvidim :) Zajtra by som na to mal mat cast

@Almindor2
Are you the same Almindor that wrote a 2D game in FreePascal a while back?

Yep, that's me, I lost my old "Almindor" login with my old ISP's email I had.

I see. By the way, whatever happened to that game of yours? Are you still developing it?
Windows - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe),
Linux Mint - Lazarus 2.1/FPC 3.2 (built using fpcupdeluxe)

mORMot; Zeos 8; SQLite, PostgreSQL & MariaDB; VirtualTreeView

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: TLTCP components problem
« Reply #11 on: April 16, 2011, 11:17:18 am »
I see. By the way, whatever happened to that game of yours? Are you still developing it?

It's "shelved" atm. The latest version works (multiplayer etc.) and is generally stable, but I have other projects (like lNet) to take care of now. Not enough time for it.

Almindor

  • Sr. Member
  • ****
  • Posts: 412
    • http://www.astarot.tk
Re: TLTCP components problem
« Reply #12 on: April 16, 2011, 12:08:19 pm »
Zdravím :D

Nejde o nic tajnýho, tak jsme to hodil na leteckou poštu: http://leteckaposta.cz/129955109

Dík moc. Taky si myslím, že to bude nějaká chujovina.

V Linuxe mi to fakci OK. Ak si zapnem server na oboch portoch a dam connect, krasne sa oba clienti pripoja, ten TCPSock posle aj nejake info a neuschyna mi to.

Jedine co som tam nasiel bol problem s INIStorage kde si nemal zadefinovany port1 pricom ho citas (padlo mi to pri StrToInt ale to som poriesil).

Este to skusim vo Windle. Mozno je problem niekde inde ako v pripojeni, napr. ten tvoj server mozno nieco posle co sa zatentuje tam (OnReceive?) ale to si ja neviem zopakovat kedze neviem co ti posle.

Skus si zatial OnReceive dat len aby vypisal texty pre obe spojenia ak ti to neuschne tak bude problem tam.


zdenal027

  • Newbie
  • Posts: 6
Re: TLTCP components problem
« Reply #13 on: April 21, 2011, 03:59:48 pm »
Ahoj,

díky za snahu. Tu chybu s INIStorage jsem si opravil, dík. Když vypisuju jen data co přijdou, je všechno ok. Problém vznikne asi někde při vykreslování došlého jpegu. Ještě k tomu zatuhnutí - nevytuhne to úplně - zatuhne video, přestane se cokoliv vypisovat do listboxů, ale dá se hýbat trackbarama a když kliknu na Send TCP paket, tak se paket opravdu odešle. Tlačítka se tváří že nereagují, ale kliknutím na Send... se ty data fakt odešlou. Jsem z toho volaký zmetený :-) Kdyžtak můžu poskytnout data co tomu chodí, jestli bys to měl jak vyzkoušet....

eny

  • Hero Member
  • *****
  • Posts: 1646
Re: TLTCP components problem
« Reply #14 on: April 21, 2011, 04:20:06 pm »
Thanks for explanation.

Exactly - when I comment out one, second runs ok. For both. I don't know if "hang" is right description - it seems that program lives - gui isn't responding, but when I click on button which sends TCP paket, paket is received on server... Strange.
Maybe the 2 components cannot run in the same (main) thread.
It might help if you put one (or both) in a separate thread.
All posts based on: Win10 (Win64); Lazarus 3_4  (x64) 25-05-2024 (unless specified otherwise...)

 

TinyPortal © 2005-2018