Lazarus

Programming => Networking and Web Programming => Topic started by: Trenatos on January 18, 2017, 05:31:26 pm

Title: Recommended socket library?
Post by: Trenatos on January 18, 2017, 05:31:26 pm
I've tried to find a socket library, and keep running into issues.

The Wiki mentioned socket_laz, which failed to install and someone mentioned was outdated, the same person recommended fpsock, which doesn't work on OSX..

Can someone please recommend a decent socket library that works on OSX?
Title: Re: Recommended socket library?
Post by: Thaddy on January 18, 2017, 05:55:19 pm
I marked socket_laz as deprecated in the wiki and a candidate for removal since you last asked  because it does not work with recent versions of Lazarus any more and has been unmaintained for 12 years. Don't use it. Don't try to use it.
FPC comes with e.g. fpsock unit in the fcl-net package and fcl-web for higher level interfaces.
I don't know if there are Laz components for them, though.
You use fcl-web and fpc-net as classes.  Both the fcl-net and fcl-web packages come with extensive examples as default.
If you installed fpc 3 you already have these packages and these are the recommended ones.

Third party components are in Indy. See http://wiki.lazarus.freepascal.org/Indy_with_Lazarus
Third part classes are in synapse. https://sourceforge.net/p/synalist/code/HEAD/tree/trunk/ Synapse is very stable and doesn't need much updates. It is maintained..
Title: Re: Recommended socket library?
Post by: Trenatos on January 18, 2017, 06:16:14 pm
So what you're saying is that it's all there, I just have no idea how to find it.

I'm going to sound pissy, but shouldn't that be something the Wiki reflects?

The sockets page for example, I saw that you updated it, not with updated info but with a Deprecated notice.  That doesn't help anyone looking for how to use sockets, it just says Here's a page with info you can't use.

I love FPC, I've used it to build and release software as well as personal projects, but I keep running into this exact issue.

Things don't work, tons of outdated info, Wiki recommends things that don't even compile, it's horribly frustrating when I just want to code and get things done, it kills productivity.

I'm not blaming anyone, I know it's a volunteer project, I just wish I knew how to help make the overall state of things better.

I wish I could make updates and write Wiki pages, but the reality is that I'm not skilled enough at Pascal to be able to write accurate information beyond basic stuff.

Aside from ranting and feeling overall defeated every time I go to make something complex, fcl-web and fpc-net are the recommended ways of handling networking/web work?  Thank you, I'll go see what info/examples/tutorials I can find on those.

I appreciate your help, I truly honestly do, I want to make sure you know I'm not complaining about you or anyone else on this forum.
Title: Re: Recommended socket library?
Post by: Thaddy on January 18, 2017, 06:45:02 pm
In your FPC directory, not Lazarus,  there is a subdirectory called packages/fcl-net and a subdirectory called packages/fcl-web.
Examine these. Both have also an examples subdirectory.... see the wiki: http://wiki.freepascal.org/fcl-net  and http://wiki.freepascal.org/fcl-web
<grumpy mode on  >:D >
Title: Re: Recommended socket library?
Post by: Trenatos on January 18, 2017, 07:17:47 pm
Thanks Thaddy, I appreciate it.

As for the wiki..  :P

fcl-net just points to the examples folder and links to an external blog.
The examples in the blog uses fpsock, which doesn't work on OSX.

The fcl-web page looks a lot more complete, hopefully nothing in there is deprecated, this will come in handy for my next project.
Title: Re: Recommended socket library?
Post by: Thaddy on January 18, 2017, 07:25:43 pm
Why would fpsock not work on OSX? The author has only MAC's  O:-) O:-) he is often accused of. I will look into it. I have a Mac mini laying around for that.
I agree the wiki references for fcl-net are rather thin - and old -, but the examples are excellent. Maybe I move some of these to the wiki with some extra text.
The wiki references are old. The sourcecode isn't.
But the wiki is maintained by users and not by the core team: they only do the documentation proper and where applicable examples.
Most, if not all, of the FCL is well maintained.
Title: Re: Recommended socket library?
Post by: Trenatos on January 18, 2017, 07:28:20 pm
Someone mentioned that fpsock is only compiled for Linux? No idea what that means in practice.
Title: Re: Recommended socket library?
Post by: Thaddy on January 18, 2017, 07:31:22 pm
That it should work on a MAC  8-) Which is at its core a unix. But I'll look into it.

Well: it works on amiga, aros,netware, netwlibc, os2, unix and windows...

Not to put too fine a point to it:
- I would have examined that subdirectory and I would have examined the sourcecode.
- That is a lot more informative than some idiots hearsay that it doesn't work on MAC. It does probably. OSX is a UNIX. Sockets are lowlevel.

Both BSD (from which OSX is a fork) and Sockets stem from Berkeley, btw. At that low a level it almost is guaranteed to work on OSX.

"Berkeley sockets is an application programming interface (API) for Internet sockets and Unix domain sockets, used for inter-process communication (IPC). It is commonly implemented as a library of linkable modules. It originated with the 4.2BSD Unix released in 1983."

[edit] It works on my intel mac mini with snow leopard. I have to test with newer versions but I expect that you should not have any problems at all..
One caveat: I often modify RTL sources - that only get noticed when I do a new checkout- and I did not use the MAC for a couple of months with FPC.
Title: Re: Recommended socket library?
Post by: Trenatos on January 18, 2017, 10:30:26 pm
When I try to use fpsock, I get an error, it definitely does not work for me, not just hearsay  ;)

Could be my version of OSX, I'm on El Capitan.

It sounded odd to me too, as I'm aware that OSX is Linux (Did not know it was a BSD fork specifically).

I did nothing special, I grabbed a new download the other day (First setup on this machine) and tried the example from the Pascal Warrior page, and immediately get an error on the uses fpsock.
Title: Re: Recommended socket library?
Post by: molly on January 18, 2017, 11:02:23 pm
When I try to use fpsock, I get an error, it definitely does not work for me, not just hearsay  ;)
Well, it seems that you are correct and fpsock was/is not compiled for mac.

fpcmake:
Code: [Select]
#
#   Makefile.fpc for FCL net units
#

[package]
name=fcl-net
version=3.0.0

[target]
units_linux=netdb resolve ssockets fpsock cnetdb
units_freebsd=netdb resolve ssockets fpsock cnetdb
units_netbsd=netdb resolve ssockets fpsock
units_openbsd=netdb resolve ssockets fpsock
units_darwin=netdb resolve ssockets
units_iphonesim=netdb resolve ssockets
units_solaris=netdb resolve ssockets
units_qnx=netdb resolve ssockets
units_beos=netdb resolve ssockets
units_haiku=netdb resolve ssockets
units_emx=resolve ssockets
units_os2=resolve ssockets
units_win32=resolve ssockets
units_win64=resolve ssockets
units_wince=resolve ssockets
units_aros=resolve ssockets

[require]
packages=fcl-base fcl-xml fcl-passrc fcl-async

[compiler]
options=-S2h
includedir=src/$(OS_TARGET)
includedir_linux=src/unix
includedir_freebsd=src/unix
includedir_darwin=src/unix
includedir_iphonesim=src/unix
includedir_netbsd=src/unix
includedir_openbsd=src/unix
includedir_solaris=src/unix
includedir_qnx=src/unix
includedir_beos=src/unix
includedir_haiku=src/unix
includedir_emx=src/os2
includedir_win32=src/win
includedir_win64=src/win
includedir_wince=src/win
sourcedir=src/$(OS_TARGET) src

[install]
fpcpackage=y

[default]
fpcdir=../..

[rules]
.NOTPARALLEL:
You should be able to use sockets using procedural approach though (fpc 3.0.0), and of course yiou can use the classes from ssockets.
Title: Re: Recommended socket library?
Post by: Trenatos on January 19, 2017, 02:40:14 am
So I grabbed the fpc 3.0.0 source off of svn, added fpsock to units_darwin and ran make cycle in fpc/compiler.

But uh, no idea what to do now..

No idea where files ended up or what to point Lazarus to..
Title: Re: Recommended socket library?
Post by: molly on January 19, 2017, 05:11:26 am
@Trenatos:
Perhaps a dumb question from my side but, what is it that you actually wish to accomplish ?

You asked specifically for sockets, and that is usually asked for a specific reason (other people normally ask for internet components/classes, tcp/ip components or similar).

That implies that you know how to handle (raw) sockets, e.g. you wish to implement your own protocols etc.
Title: Re: Recommended socket library?
Post by: Trenatos on January 19, 2017, 05:47:40 am
Several reasons actually.

I wrote a simple IRC client in LiveCode a few years back, I want to take a proper stab at that again and expand on it as I got inspired by Slack, I'm also planning to implement a simple table top-style game in a network fashion.

Yes, I'll be writing my own protocols, for sockets I'm just looking at networking, I won't be dealing with complex data for any of this.

I'm a web developer by profession, so yeah I'm also looking at using FPC/Lazarus as a web stack (Possibly with Brook, but surprise-surprise, it doesn't compile on El Capitan..), but that's what I do for a living, the socket stuff is mostly for fun.

As for what I'm trying to accomplish with compiling FPC is just me trying to move forward and testing to see if just adding fpsock to the units_darwin works, solving my own problem rather than hoping that someone else takes enough pity on me to do it.

I do try to solve my own problems first, but I ran into the issue above, I compiled it but now what?.. lol
Title: Re: Recommended socket library?
Post by: molly on January 19, 2017, 06:05:02 am
@Trenatos:
Ok, i did not wanted to sound too nosy. Just thought it was perhaps better to recommend to use a ready to go (more extended) framework.

Alas, i know that situation all to well that not all platforms are supported  :'(

Ok, i don't believe an irc example is available but, recently someone wanted to create his/her own http server, here (http://forum.lazarus.freepascal.org/index.php/topic,35438.0.html). Just ignore the winsock part there  ;)

In case you've compiled your own fpsock unit then it is located probably in the place where you compiled it, e.g. inside fcl-net directory of your sources (no clue as of what exactly you did to compile it). In case of a installed fpc/lazarus, copy the unit (and/or sources) over to your installation. you should be looking for "fpsock.ppu".

A simple uses fpsock should be enough. Do relaize that there might be a perfectly valid reason why fpsock is not compiled for darwin by default (deprecated for example). units sockets and ssocket can be used as well.

fcl-web complements fcl-net and provides some examples such as a simple http server and also a simple http client.

Title: Re: Recommended socket library?
Post by: Thaddy on January 19, 2017, 10:16:11 am
Can you give me some more information about the error you get.
You can simply add the path to the sources and try again.
I have no clue why fpsock is not compiled as package for OSX.
As I said: I can use it, but maybe I made some changes. I will try and find what I did exactly.
It can also be the case that it used to be enabled and is now disabled for some reason I am not aware of.
Title: Re: Recommended socket library?
Post by: marcov on January 19, 2017, 10:21:01 am
When I try to use fpsock, I get an error, it definitely does not work for me, not just hearsay  ;)
Well, it seems that you are correct and fpsock was/is not compiled for mac.

fpcmake:

(in 3.0+ the authoritative source is fpmake.pp btw, not makefile.fpc, which is only kept for certain developer purposes,
but in this case the result is the same
Title: Re: Recommended socket library?
Post by: marcov on January 19, 2017, 10:26:16 am
Why would fpsock not work on OSX? The author has only MAC's  O:-) O:-) he is often accused of.

From fpsock.pp

Quote
Socket communication components
    Copyright (c) 2003 by
      Areca Systems GmbH / Sebastian Guenther, sg@freepascal.org


I never saw Sebastian use a Mac, except when I forced him too (he compiled QT on my mac mini during a fair in Muenchen to demonstrate the first time I saw QT Lazarus on the Mac). It took 8+ hours or so :-)

When Sebastian was active in the project (mostly before 2.0), FPC didn't even exist on the Mac. He was an avid Linux user, but did some work on Windows too due to client requests.

Of course, meanwhile 10 years have passed and he could be using nearly anything  :-)
Title: Re: Recommended socket library?
Post by: Thaddy on January 19, 2017, 11:16:39 am
Ah. I mixed up, Marco
Anyway, there are maintainers ;)
Can somebody else test from the sources too. Afaict fpsock (fcl-net as a whole maybe not, didn't test that) can be enabled for OSX. It is all based on lowlevel unix units and these all work on OSX. That also goes for fcl-async, which is a dependency.
Title: Re: Recommended socket library?
Post by: Thaddy on January 19, 2017, 12:19:49 pm
Oops:

I am examining why my code works. It's a bit of a mess.
- I copied the FreeBSD sockets sources and includes to my project directory
- I copied the fcl-net sources to my project directory
- I copied the fcl-async sources to my project directory.
- I changed the value of MSG_NOSIGNAL from $20000 to 0. I have no clue why, doesn't look right. (On Linux it is $4000 on FreeBSD and OpenBSD it is $20000, $4000 is MSG_NBIO on BSD's) I seem to remember I did that for synapse to work (which it does)

I have also messed with libc at some point, but it seems that that is not used anymore.

Even if it's a mess. It works, but I have to test and recompile. Report back later. If it STILL works I will prepare the files so it can be enabled on OSX (at least snow leopard)

ATM, unless you a prepared to take these steps,I must say I was probably wrong in over hastily recommending fpsock.  :( :( >:(
Anyway, I dusted off the mac mini  ::)
Title: Re: Recommended socket library?
Post by: molly on January 19, 2017, 07:32:50 pm
When I try to use fpsock, I get an error, it definitely does not work for me, not just hearsay  ;)
Well, it seems that you are correct and fpsock was/is not compiled for mac.

fpcmake:
(in 3.0+ the authoritative source is fpmake.pp btw, not makefile.fpc, which is only kept for certain developer purposes,
but in this case the result is the same
Oops, my bad. Thank you for the correction.
Title: Re: Recommended socket library?
Post by: Trenatos on January 20, 2017, 04:09:00 am
@molly Nah you're not nosy, no worries.

I really appreciate the help from everyone.

I don't really know enough to see if this can just be turned back on for OSX in the official repos, would love that of course though.

I'll see if I can make my local copy work in the mean time.

Someone mentioned fpweb, I've started playing with that today, pretty neat so far, going to be fun pitting it against my usual stack and see how it performs   :)
Title: Re: Recommended socket library?
Post by: trev on May 03, 2021, 12:00:21 pm
To bring this thread to its conclusion:

* fpsock.pp is still not enabled for macOS;
* However, it compiles if you copy it to your project directory, include it in your Uses clause, and edit it to replace MSG_NOSIGNAL with SO_NOSIGPIPE and appears to work without issue.

I guess I should log a bug...
TinyPortal © 2005-2018