How to implement a simple tcp/ip connection?

classic Classic list List threaded Threaded
17 messages Options
Reply | Threaded
Open this post in threaded view
|

How to implement a simple tcp/ip connection?

Giuliano Colla
Hi all,

I need to implement a simple dedicated TCP/IP connection between a
client and a server. Nothing fancy, just sending and receiving short
strings. I have used in the past for that purpose the unit Sockets
lifting it from Kylix. This unit was taking advantage of libc, and this
rules it out.

I see that fpc provides a Socket unit in rtl-extra and a fpSock unit in
fcl-net. At first glance they both appear to provide what I need.

Can somebody which has used those units point me in the right direction,
before I painfully study in detail those units.

Thanks for any help.

Giuliano

--
Do not do to others as you would have them do to you.They might have different tastes.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Luca Olivetti-2
El 14/5/20 a les 18:21, Giuliano Colla ha escrit:
> Hi all,
>
> I need to implement a simple dedicated TCP/IP connection between a
> client and a server. Nothing fancy, just sending and receiving short
> strings. I have used in the past for that purpose the unit Sockets
> lifting it from Kylix. This unit was taking advantage of libc, and this
> rules it out.

If the problem is the unit libc but you can accept that the project is
using  libc.so the ararat synape is another alternative.
I started using it when I abandoned delphi for lazarus and I still use
it to this day (mostly windows though).

Bye
--
Luca
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Michael Van Canneyt
In reply to this post by Giuliano Colla


On Thu, 14 May 2020, Giuliano Colla wrote:

> Hi all,
>
> I need to implement a simple dedicated TCP/IP connection between a
> client and a server. Nothing fancy, just sending and receiving short
> strings. I have used in the past for that purpose the unit Sockets
> lifting it from Kylix. This unit was taking advantage of libc, and this
> rules it out.
>
> I see that fpc provides a Socket unit in rtl-extra and a fpSock unit in
> fcl-net. At first glance they both appear to provide what I need.
>
> Can somebody which has used those units point me in the right direction,
> before I painfully study in detail those units.

The TFTPHTTPClient and server components both use fpSock.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Alexander Grotewohl
In reply to this post by Giuliano Colla
the sockets unit should work exactly like any tutorial for c sockets for linux. a handful of the functuons need an fp prefix but should work mostly the same.

--
Alexander Grotewohl


From: fpc-pascal <[hidden email]> on behalf of Giuliano Colla <[hidden email]>
Sent: Thursday, May 14, 2020 12:21:36 PM
To: FPC-Pascal users discussions <[hidden email]>
Subject: [fpc-pascal] How to implement a simple tcp/ip connection?
 
Hi all,

I need to implement a simple dedicated TCP/IP connection between a
client and a server. Nothing fancy, just sending and receiving short
strings. I have used in the past for that purpose the unit Sockets
lifting it from Kylix. This unit was taking advantage of libc, and this
rules it out.

I see that fpc provides a Socket unit in rtl-extra and a fpSock unit in
fcl-net. At first glance they both appear to provide what I need.

Can somebody which has used those units point me in the right direction,
before I painfully study in detail those units.

Thanks for any help.

Giuliano

--
Do not do to others as you would have them do to you.They might have different tastes.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Free Pascal - General mailing list
In reply to this post by Giuliano Colla
On Thu, 14 May 2020 18:21:36 +0200, Giuliano Colla
<[hidden email]> wrote:

>I see that fpc provides a Socket unit in rtl-extra and a fpSock unit in
>fcl-net. At first glance they both appear to provide what I need.

LNet is a package that contains useful socket classes and refer back
to sockets. Can be installed into Lazarus via OnLine Package Manager.


--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Giuliano Colla
Thank you to all of you guys. Now I have a much better picture

--
Do not do to others as you would have them do to you.They might have different tastes.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Graeme Geldenhuys-6
In reply to this post by Giuliano Colla
On 14/05/2020 5:21 pm, Giuliano Colla wrote:
> I need to implement a simple dedicated TCP/IP connection between a
> client and a server.

You can always use the Indy TCP components too. I've used them for years
under Delphi and FPC with great success. Huge amounts of protocols are
implement and loads of examples available.

  SVN:  svn.atozed.com
  Git (mirror):  github.com/graemeg/indy


Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Free Pascal - General mailing list
On Thu, 14 May 2020 22:02:01 +0100, Graeme Geldenhuys
<[hidden email]> wrote:

>On 14/05/2020 5:21 pm, Giuliano Colla wrote:
>> I need to implement a simple dedicated TCP/IP connection between a
>> client and a server.
>
>You can always use the Indy TCP components too. I've used them for years
>under Delphi and FPC with great success. Huge amounts of protocols are
>implement and loads of examples available.
>
>  SVN:  svn.atozed.com
>  Git (mirror):  github.com/graemeg/indy
>

Well the simplest way to get Indy10 into Lazarus is via Online Package
Manager! Searh for Indy and it will find Indy10 for you.
THe package is named indylaz.

That said (I also use Indy a lot) if one converts a program from
Delphi where one has used the TServerSocket or TClientSocket classes
it is a rather steep climb since Indy10 is entirely blocking and the
Delphi components were event driven.

I am myself struggling with this problem right now converting an old
Windows service application that is configured from a Delphi
programmed client operating over TCP/IP sockets. And it uses
TClientSocket and TServerSocket....
I am going to try LNet hoping it will not bee too different from the
Delphi native components...
(Note: Delphi 7/Delphi 2007)


--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Graeme Geldenhuys-6
On 16/05/2020 7:13 pm, Bo Berglund via fpc-pascal wrote:
>
> Well the simplest way to get Indy10 into Lazarus is via Online Package
> Manager!

Do they (whoever it might be) keep it up to date with the lastest Indy?

> it is a rather steep climb since Indy10 is entirely blocking and the
> Delphi components were event driven.

Indy devs explain it here. Blocking is not evil.

  https://www.swissdelphicenter.ch/en/showarticle.php?id=4


Regards,
  Graeme

--
fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal
http://fpgui.sourceforge.net/

My public PGP key:  http://tinyurl.com/graeme-pgp
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Free Pascal - General mailing list
On Sat, 16 May 2020 23:24:34 +0100, Graeme Geldenhuys
<[hidden email]> wrote:

>> Well the simplest way to get Indy10 into Lazarus is via Online Package
>> Manager!
>
>Do they (whoever it might be) keep it up to date with the lastest Indy?

I believe that it is actually Remy Lebeau who is doing that (I might
be wrong)..
In any case I received Indy 10.6.2 when I installed through OPM from
Lazarus 2.0.8 on Windows.

>> it is a rather steep climb since Indy10 is entirely blocking and the
>> Delphi components were event driven.
>
>Indy devs explain it here. Blocking is not evil.
>
>  https://www.swissdelphicenter.ch/en/showarticle.php?id=4

Yes, I know that it is not evil, but if you are stuck with a rather
big Delphi application that is proven to work with the TServerSocket
and using events to handle "everything" then it is much more difficult
to turn to Indy during porting to FPC and then on to Linux...

As you might have seen in various posts I have made recently I am
trying to port a Windows service application written in
Delphi7/Delphi2007 running on Windows to FPC/Lazarus in order to then
move on to Linux.

I have worked my way through it in Delphi 2007 to add ifdefs in a lot
of places in order to prepare for the conversion into Lazarus and now
I am in Lazarus trying to weed out the remaining issues. Not close
yet...
But it seems like my use of LNet in any case has been accepted by
FPC/Lazarus as a replacement for TServerSocket.


--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Giuliano Colla
In reply to this post by Free Pascal - General mailing list
I'm struggling with a similar problem. It would appear that the easiest
way would be just take advantage of the Sockets unit. You only must
define some more constants, such as SO_REUSEPORT and SOCK_NONBLOCK which
are missing in fpc.

I just made some preliminary tests, and it looks like it's not so
difficult to implement something quite compatible with Delphi
philosophy. The SOCK_NONBLOCK flag is one of the keys.

Now I'm planning to look in more detail the old Delphi implementation,
in order to see how they were tacking advantage of Libc. If you're
interested I'll let you know my results.

Giuliano


Il 16/05/2020 20:13, Bo Berglund via fpc-pascal ha scritto:
> I am myself struggling with this problem right now converting an old
> Windows service application that is configured from a Delphi
> programmed client operating over TCP/IP sockets. And it uses
> TClientSocket and TServerSocket....
> I am going to try LNet hoping it will not bee too different from the
> Delphi native components...
> (Note: Delphi 7/Delphi 2007)

--
Do not do to others as you would have them do to you.They might have different tastes.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Michael Van Canneyt


On Tue, 19 May 2020, Giuliano Colla wrote:

> I'm struggling with a similar problem. It would appear that the easiest
> way would be just take advantage of the Sockets unit. You only must
> define some more constants, such as SO_REUSEPORT and SOCK_NONBLOCK which
> are missing in fpc.

They are not missing.

How do you think fpsock and lnet implement non-blocking ?
It's simply called  O_NONBLOCK.

For some reason, SO_REUSEPORT was commented for linux, I uncommented it.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Alexander Grotewohl
It was added for Linux 3.9 in 2013.. maybe the code predates that?

--
Alexander Grotewohl
https://dcclost.com

From: fpc-pascal <[hidden email]> on behalf of Michael Van Canneyt <[hidden email]>
Sent: Tuesday, May 19, 2020 12:57:37 PM
To: FPC-Pascal users discussions <[hidden email]>
Cc: [hidden email] <[hidden email]>
Subject: Re: [fpc-pascal] How to implement a simple tcp/ip connection?
 


On Tue, 19 May 2020, Giuliano Colla wrote:

> I'm struggling with a similar problem. It would appear that the easiest
> way would be just take advantage of the Sockets unit. You only must
> define some more constants, such as SO_REUSEPORT and SOCK_NONBLOCK which
> are missing in fpc.

They are not missing.

How do you think fpsock and lnet implement non-blocking ?
It's simply called  O_NONBLOCK.

For some reason, SO_REUSEPORT was commented for linux, I uncommented it.

Michael.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Giuliano Colla
In reply to this post by Michael Van Canneyt
Il 19/05/2020 18:57, Michael Van Canneyt ha scritto:

> They are not missing.
>
> How do you think fpsock and lnet implement non-blocking ?
> It's simply called  O_NONBLOCK.

I'm using fpc 3.0.4. With just Sockets in the uses clause both
SOCK_NONBLOCK and O_NONBLOCK give an Identifier not found error.
I've seen that SO_REUSEPORT was commented out, so I just defined it in
my code.

--
Do not do to others as you would have them do to you.They might have different tastes.

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Norbert Saint Georges
Giuliano Colla a écrit :

> Il 19/05/2020 18:57, Michael Van Canneyt ha scritto:
>
>> They are not missing.
>>
>> How do you think fpsock and lnet implement non-blocking ?
>> It's simply called  O_NONBLOCK.
>
> I'm using fpc 3.0.4. With just Sockets in the uses clause both SOCK_NONBLOCK
> and O_NONBLOCK give an Identifier not found error.
> I've seen that SO_REUSEPORT was commented out, so I just defined it in my
> code.

With lnet I use:
fsock.SetState (ssBlocking, false);
fsock.SetState (ssReuseAddress, true);

--
Norbert Saint Georges
http://tetrasys.fi

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Michael Van Canneyt
In reply to this post by Giuliano Colla


On Tue, 19 May 2020, Giuliano Colla wrote:

> Il 19/05/2020 18:57, Michael Van Canneyt ha scritto:
>
>> They are not missing.
>>
>> How do you think fpsock and lnet implement non-blocking ?
>> It's simply called  O_NONBLOCK.
>
> I'm using fpc 3.0.4. With just Sockets in the uses clause both SOCK_NONBLOCK
> and O_NONBLOCK give an Identifier not found error.
> I've seen that SO_REUSEPORT was commented out, so I just defined it in my
> code.
You'll need the unix/baseunix unit for O_NONBLOCK.

I believe on windows there is a similar define, but I'm not sure where.
It must exist, because the non-blocking works cross-platform.

Michaem.
_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: How to implement a simple tcp/ip connection?

Free Pascal - General mailing list
In reply to this post by Giuliano Colla
On Tue, 19 May 2020 18:25:54 +0200, Giuliano Colla
<[hidden email]> wrote:

>Now I'm planning to look in more detail the old Delphi implementation,
>in order to see how they were tacking advantage of Libc. If you're
>interested I'll let you know my results.
>

Yes, please!


--
Bo Berglund
Developer in Sweden

_______________________________________________
fpc-pascal maillist  -  [hidden email]
https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal