Looking for simple socket console example, rtl doc exaple does not seem to work lazarus / 38-Networking and Web Programming ---------------------------------------------------------------------- RickD · 2016-12-12 09:56 Hello all, I'm trying to compile the socket examples which can be found here and create a basic server an client executable to experiment with. http://www.freepascal.org/docs-html/current/rtl/sockets/accept.html http://www.freepascal.org/docs-html/current/rtl/sockets/connect.html However the server part doesn't seem to compile using fpc 2.6 on windows (see screen output of errors). --- C:\temp\fpc server.pas Free Pascal Compiler version 2.6.4 [2014/03/06] for i386 Copyright (c) 1993-2014 by Florian Klaempfl and others Target OS: Win32 for i386 Compiling server.pas server.pas(39,23) Error: Call by var for arg no. 2 has to match exactly: Got "ShortString" expected "sockaddr_in" server.pas(40,33) Warning: Variable "FromName" does not seem to be initialized server.pas(50,4) Fatal: There were 1 errors compiling module, stopping Fatal: Compilation aborted Error: C:\FPC\2.6.4\bin\i386-Win32\ppc386.exe returned an error exitcode (normal if you did not specify a source file to be compiled) --- Can anybody help me fix this so it compiles and works as described or point me to another basic fpc socket example that works? I just need a basic console based framework that can send bytes from a client to server and back without using external libraries. There seems to be a lot of c code around but no pascal based examples. Thanks in advace for any help! Regards, Rick ---------------------------------------------------------------------- mlody87 · 2016-12-12 10:25 You can use lNet component. For client and server console example clicke here http://forum.lazarus.freepascal.org/index.php?topic=18736.0 ---------------------------------------------------------------------- bee · 2016-12-12 11:28 Quote from: RickD on December 12, 2016, 10:56:11 amI'm trying to compile the socket examples which can be found here and create a basic server an client executable to experiment with. http://www.freepascal.org/docs-html/current/rtl/sockets/accept.html http://www.freepascal.org/docs-html/current/rtl/sockets/connect.html I tried the example given in the docs on Ubuntu Linux using FPC v3. It compiled fine but shows some warnings. For the server side code: ——— $ fpc -XXs -CX -O3 -S2achi server.pas -Fu/home/cabox/pascal Free Pascal Compiler version 3.0.0 [2015/11/20] for x86_64 Copyright (c) 1993-2015 by Florian Klaempfl and others Target OS: Linux for x86-64 Compiling server.pas server.pas(33,6) Warning: Symbol "Accept" is deprecated Linking server 43 lines compiled, 0.1 sec 1 warning(s) issued ——— For the client side code: ——— $ fpc -XXs -CX -O3 -S2achi client.pas -Fu/home/cabox/pascal Free Pascal Compiler version 3.0.0 [2015/11/20] for x86_64 Copyright (c) 1993-2015 by Florian Klaempfl and others Target OS: Linux for x86-64 Compiling client.pas client.pas(29,26) Warning: Symbol "HostToNet" is deprecated client.pas(30,10) Warning: Symbol "Connect" is deprecated Linking client 40 lines compiled, 0.1 sec 2 warning(s) issued ——— However, when both are executed, the server side produces wrong string. ——— cabox@box:~$ ./server Waiting for Connect from Client, run now sock_cli in an other tty Server : Accept : �0 ——— I think both the documentation and the sample code need to be reviewed and updated. Because they're using deprecated methods and the sample doesn't work as expected. ---------------------------------------------------------------------- bee · 2016-12-12 11:30 Quote from: mlody87 on December 12, 2016, 11:25:09 amYou can use lNet component. For client and server console example clicke here http://forum.lazarus.freepascal.org/index.php?topic=18736.0 He doesn't want to use external or third party libraries. Besides, for such simple task, the provided FPC's networking unit should be sufficient. ---------------------------------------------------------------------- Leledumbo · 2016-12-12 14:40 The not-so-simple (no external libraries, but it uses fcl-net functionality instead of just the rtl) example can be read on my old blogpost: http://pascalgeek.blogspot.co.id/2012/06/encryption- decryption-and-asynchronous.html However, if you have existing C code, it should be convertible rather straightforwardly to Pascal (provided you know both languages just as well). Just prepend all the BSD socket functions' name with fp prefix, the semantic should be equivalent. ---------------------------------------------------------------------- dinmil · 2016-12-12 15:01 If you write your own server and client then try to use ZeroMQ instead of sockets. It is similar but more powerfull. Hoewer zeromq requires third party dll, but check it out www.danieleteti.it/using-amqp-from-delphi-with-zeromq/ zguide.zeromq.org/page:all zeromq.wdfiles.com/local--files/intro%3A...20Leaders%202011.pdf Checkout github for zeromq pascal and delphi. I think there are 3 libraries that cover this area. ---------------------------------------------------------------------- RickD · 2016-12-16 20:05 Quote from: mlody87 on December 12, 2016, 11:25:09 amYou can use lNet component. For client and server console example clicke here http://forum.lazarus.freepascal.org/index.php?topic=18736.0 Thanks all for your input. I tested the lnet code and it compiled (with a few warnings), and the console examples did seem to work fine, so i guess i'm gonna go with that one as a second best (no dll needed, works in console mode, just needs to link some units which makes it a bit larger than rtl). Too bad the rtl is code is broken. They should remove all the broken stuff from rtl to avoid confusion and save people from spending any puzzle time on it. Regards, Rick ---------------------------------------------------------------------- marcov · 2016-12-16 20:12 The example problem works on *nix, since versions that take a string are *nix only. They are also marked deprecated, but the documentation tool doesn't show this.