Recent

Author Topic: fpsockets error: 10047  (Read 1631 times)

senglit

  • Full Member
  • ***
  • Posts: 141
fpsockets error: 10047
« on: December 10, 2025, 04:18:59 am »
Hi,

I'm trying to learn how to use fpsockets unit in FPC trunk (win11, FPC 3.3.1, lazarus 4.4). But I am stopped at the first step. Please see the code bellow, which I copied from tfpsock2.pp

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. var
  3.   mySock:TFPSocket;
  4.   Received: TReceiveFromStringMessage;
  5.   ClientError:string = '';
  6. begin
  7.   try
  8.     mySock := UDPSocket(stIPv4);
  9.     try
  10.       Sleep(50);
  11.       SendStrTo(mySock, '127.0.0.1', 1337, 'hello from client');
  12.       Sleep(50);
  13.       Received := ReceiveStrFrom(mySock, 16);
  14.     finally
  15.       CloseSocket(mySock);
  16.     end;
  17.     if Received.Data <> 'hello from server' then
  18.       ClientError := 'Unexpected response: ' + Received.Data;
  19.   except on E: Exception do
  20.     ClientError := 'Exception: ' + E.Message;
  21.   end;
  22. end;    
  23.  

It got error at SendStrTo. Please find the error message in the attached.

Anything wrong with this fpsockets unit? Or I used it in a wrong way?

BTW, I got some other questions about fpsockets:
1. The ReceiveStr function does not have a parameter like TimeOut. So will it be blocked until a string come?
2. I guess SetNonBlocking(sock, True) and ReceiveStrFromNonBlocking will check if there any data in the buffer, and it will return immediately if the buffer is empty, And then I need to implement timeout function by myself, Am I right?
3. How to enlarge the buffer size?
I use Win11 + Lazarus3.6 + FPC Trunk. fpcupdeluxe

Thaddy

  • Hero Member
  • *****
  • Posts: 18712
  • To Europe: simply sell USA bonds: dollar collapses
Re: fpsockets error: 10047
« Reply #1 on: December 10, 2025, 10:55:05 am »
You should really look at the examples in./packages/fcl-net/examples , not copy code from irrelevant sources. The examples are clear and all work.
It would solve your question(s) in minutes.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

senglit

  • Full Member
  • ***
  • Posts: 141
Re: fpsockets error: 10047
« Reply #2 on: December 10, 2025, 11:27:07 am »
There is no example of fpsockets unit in ./packages/fcl-net/examples.

I used the code from https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-net/tests/tfpsock2.pp?ref_type=heads

Edit:
Also can be found in .packages/fcl-net/tests/tfpsock2.pp

You should really look at the examples in./packages/fcl-net/examples , not copy code from irrelevant sources. The examples are clear and all work.
It would solve your question(s) in minutes.
« Last Edit: December 10, 2025, 11:32:15 am by senglit »
I use Win11 + Lazarus3.6 + FPC Trunk. fpcupdeluxe

rvk

  • Hero Member
  • *****
  • Posts: 6925
Re: fpsockets error: 10047
« Reply #3 on: December 10, 2025, 11:54:24 am »
There is no example of fpsockets unit in ./packages/fcl-net/examples.

I used the code from https://gitlab.com/freepascal.org/fpc/source/-/blob/main/packages/fcl-net/tests/tfpsock2.pp?ref_type=heads
Did you use the exact code ????
Didn't you mis a Bind() call in there ???


Sorry, that's for server.
« Last Edit: December 10, 2025, 11:56:12 am by rvk »

tetrastes

  • Hero Member
  • *****
  • Posts: 734
Re: fpsockets error: 10047
« Reply #4 on: December 10, 2025, 12:05:44 pm »
Anything wrong with this fpsockets unit? Or I used it in a wrong way?

Yes you do.
Study the test file you cited, especially

Code: Pascal  [Select][+][-]
  1. procedure RunTest(const TestName: String; ASrv, ACli: TProcedure);

and try to understand how it works.

senglit

  • Full Member
  • ***
  • Posts: 141
Re: fpsockets error: 10047
« Reply #5 on: December 10, 2025, 12:21:01 pm »
Anything wrong with this fpsockets unit? Or I used it in a wrong way?

Yes you do.
Study the test file you cited, especially

Code: Pascal  [Select][+][-]
  1. procedure RunTest(const TestName: String; ASrv, ACli: TProcedure);

and try to understand how it works.

the procedure RunTest seems doesn't do anything special but to run both server procedure and client procedure as threads so that they can communicate to each other. If the client procedure it's self can not run properly how the thread can run? Actually the unit tfpsock2.pp was reported the same error as I posted.
I use Win11 + Lazarus3.6 + FPC Trunk. fpcupdeluxe

tetrastes

  • Hero Member
  • *****
  • Posts: 734
Re: fpsockets error: 10047
« Reply #6 on: December 10, 2025, 12:42:20 pm »
Well... It's a trunk...

In my one-year-old trunk it's OK:

D:\Programs\fpcup32-trunk\fpcsrc\packages\fcl-net\tests>D:\Programs\fpcup32-trunk\fpc\bin\i386-win32\ppcrossx64.exe tfpsock2.pp -O3
Free Pascal Compiler version 3.3.1-16887-g7ac4e38b71 [2024/11/12] for x86_64
Copyright (c) 1993-2024 by Florian Klaempfl and others
Target OS: Win64 for x64
Compiling tfpsock2.pp
fpsockets.pp(870,7) Warning: Unreachable code
fpsockets.pp(870,7) Warning: Unreachable code
fpsockets.pp(875,3) Warning: Unreachable code
fpsockets.pp(897,7) Warning: Unreachable code
fpsockets.pp(904,3) Warning: Unreachable code
fpsockets.pp(804,7) Warning: Unreachable code
fpsockets.pp(837,7) Warning: Unreachable code
Linking tfpsock2.exe
564 lines compiled, 0.3 sec, 221072 bytes code, 10564 bytes data
7 warning(s) issued

D:\Programs\fpcup32-trunk\fpcsrc\packages\fcl-net\tests>tfpsock2.exe
Testing IPv4Test... Success!
Testing IPv6Test... Success!
Testing DualStackTest... Success!
Testing DataAvailableTest... Success!
Testing ReceiveArrayTest... Success!
Testing ChunkTest... Success!
Testing UDPFragmentationTest... Success!
Testing NonBlockingTest... Success!
Testing FragmentationTest... Success!
Testing FragmentedArrayTest... Success!

cdbc

  • Hero Member
  • *****
  • Posts: 2576
    • http://www.cdbc.dk
Re: fpsockets error: 10047
« Reply #7 on: December 10, 2025, 12:50:46 pm »
Hi
Yes the demoes work just fine, albeit - they are smeared in /generics/, that's where the "Unreachable code" stems from...

· Build yourself a working UDP-server first, thats dead easy...
· Then create the client while having the server running in the background...

Because the demos uses threads, you don't notice that you have to have the 2 client and server separated. Build 2 apps, by far the easiest approach.
...And keep the generics to a minimum -- You'll thank me later!
Regards Benny
If it ain't broke, don't fix it ;)
PCLinuxOS(rolling release) 64bit -> KDE6/QT6 -> FPC Release -> Lazarus Release &  FPC Main -> Lazarus Main

senglit

  • Full Member
  • ***
  • Posts: 141
Re: fpsockets error: 10047
« Reply #8 on: December 10, 2025, 01:25:25 pm »
Hi
Yes the demoes work just fine, albeit - they are smeared in /generics/, that's where the "Unreachable code" stems from...

· Build yourself a working UDP-server first, thats dead easy...
· Then create the client while having the server running in the background...

Because the demos uses threads, you don't notice that you have to have the 2 client and server separated. Build 2 apps, by far the easiest approach.
...And keep the generics to a minimum -- You'll thank me later!
Regards Benny

I think it's nothing to do with server and client. It's udp. the client can work without a server and the message sent by client will just be eaten by the network and the client can not receive any response from the server. But it should not report an error. I also build tfpsock2.pp in fpc trunk and lazarus-stable. It does not work.

It seems something wrong with the trunk in this state. My trunk version was installed by fpcupdeluxe 2 days ago. I failed while install and report the bug and it's fixed in 20 minutes then I can install. I guess something in lower layer of fpsockes is modified.
I use Win11 + Lazarus3.6 + FPC Trunk. fpcupdeluxe

rvk

  • Hero Member
  • *****
  • Posts: 6925
Re: fpsockets error: 10047
« Reply #9 on: December 10, 2025, 01:27:41 pm »
This might be a problem in latest trunk (and the one from 1 or 2 months ago).
In my november trunk 64 bit the test-project gave the same error.
I freshly compiled a new 32 bit trunk and that one fails too.

32 bit trunk from july is ok.
So this is definitely a bug.

You can submit a bugreport.
« Last Edit: December 10, 2025, 02:05:11 pm by rvk »

Thaddy

  • Hero Member
  • *****
  • Posts: 18712
  • To Europe: simply sell USA bonds: dollar collapses
Re: fpsockets error: 10047
« Reply #10 on: December 10, 2025, 06:33:52 pm »
Hi
Yes the demoes work just fine, albeit - they are smeared in /generics/, that's where the "Unreachable code" stems from...
No, the unreachable code warnings stem from the callbacks that the compiler "sees" as unreachable. This has always been the case.
Since the callbacks are basically pointer types, this is extremely difficult/impossible to solve.

Anyway: I tested the examples this morning - not all of them - with a trunk from today on 64 bit Linux and the tested ones simply work.

@tetrates
A trunk from a year old is not a trunk but you can use it to find the regression.

In general there have been quite a few changes this year, so it is perfectly possible that 32 bit platforms are affected. But I refuse to build for 32 bit on 64 bit platforms.
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

rvk

  • Hero Member
  • *****
  • Posts: 6925
Re: fpsockets error: 10047
« Reply #11 on: December 10, 2025, 06:39:52 pm »
Anyway: I tested the examples this morning - not all of them - with a trunk from today on 64 bit Linux and the tested ones simply work.
Seeing the image in opening post OP is on Windows.
I tested it with a fresh trunk for Windows and there it fails.

A trunk version from July worked fine.
So it's because of changes since then.

Thaddy

  • Hero Member
  • *****
  • Posts: 18712
  • To Europe: simply sell USA bonds: dollar collapses
Re: fpsockets error: 10047
« Reply #12 on: December 10, 2025, 07:25:00 pm »
Yes if it is a regression it needs a git bisect based on date, not commit (also, add OS and bitness to bug report, so Windows 32 bit). That's the fastest way to find it, but I am not a git guru.
« Last Edit: December 10, 2025, 07:26:42 pm by Thaddy »
If Europe sells their USA bonds the USD will collapse. Europe can affort that given average state debts. The USA can't affort that. Just an advice...

bytebites

  • Hero Member
  • *****
  • Posts: 776
Re: fpsockets error: 10047
« Reply #13 on: December 10, 2025, 09:58:18 pm »
Quote
aaa50b7cbda6ba65b58320be7eff4e5f128f4100 is the first bad commit
commit aaa50b7cbda6ba65b58320be7eff4e5f128f4100
Author: Michaël Van Canneyt <michael@freepascal.org>
Date:   Mon Jul 28 22:48:29 2025 +0200

    * Amiga needs exact address size.

 packages/fcl-net/src/fpsockets.pp | 91 ++++++++++++++++++++++++++-------------
 packages/fcl-net/src/ssockets.pp  | 28 +++++++++---
 2 files changed, 84 insertions(+), 35 deletions(-)

tetrastes

  • Hero Member
  • *****
  • Posts: 734
Re: fpsockets error: 10047
« Reply #14 on: December 11, 2025, 09:15:16 am »
@tetrates
A trunk from a year old is not a trunk...

And what is it? Release?  :D

 

TinyPortal © 2005-2018