Recent

Author Topic: cannot receive messages; udp server with lnet  (Read 6120 times)

prodingus

  • Jr. Member
  • **
  • Posts: 74
cannot receive messages; udp server with lnet
« on: July 01, 2022, 01:04:42 am »
Hi!

the client works just fine:

Code: Pascal  [Select][+][-]
  1. program test1;
  2. {$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
  3. {$APPTYPE CONSOLE}
  4. uses
  5.         sysutils, crt, lnet;
  6. var
  7.         Sock:TLUDP;
  8. begin
  9.        
  10.     Sock:= TLUdp.Create(nil);
  11.     Sock.connect('1.1.1.2', 28);
  12.  
  13.     repeat
  14.     Sock.sendmessage('ghj');
  15.     until false;
  16.  
  17.  
  18. end.

on the "server" I use the hercules utility to see the data (and I see them just fine).

However, when using this code to make my version of server:

Code: Pascal  [Select][+][-]
  1. program test1;
  2. {$IFDEF FPC}{$MODE DELPHI}{$ENDIF}
  3. {$APPTYPE CONSOLE}
  4. uses
  5.         sysutils, crt, lnet;
  6. var
  7.         Sock:TLUDP;
  8.         tmp: string;
  9. begin
  10.        
  11.         Sock:= TLUdp.Create(nil);
  12.     //Sock.connect('1.1.1.2', 28);
  13.         Sock.listen(word('28'));
  14.  
  15.     repeat begin
  16.     Sock.getmessage(tmp);
  17.     writeln(Sock.getmessage(tmp));
  18.  
  19.     sleep(100);
  20.     end; until false;
  21.  
  22.  
  23. end.

I get nothing. Can anyone provide a barebone "get udp message loop" example without classes, methods  and stuff?
lazarus 1.6, FPC 3.0, SVN 51630.

derek.john.evans

  • Jr. Member
  • **
  • Posts: 55
Re: cannot receive messages; udp server with lnet
« Reply #1 on: July 01, 2022, 01:38:38 am »
What is up wth this line?
Code: Pascal  [Select][+][-]
  1. Sock.listen(word('28'));

Check the examples folder for lnet. There is an example called: packages/lnet/examples/console/ludp/ludp.pp
« Last Edit: July 01, 2022, 01:40:12 am by derek.john.evans »

prodingus

  • Jr. Member
  • **
  • Posts: 74
Re: cannot receive messages; udp server with lnet
« Reply #2 on: July 01, 2022, 01:46:11 am »
I did. The "word('28')" works only that way as it throws "constant string", expected "word".
lazarus 1.6, FPC 3.0, SVN 51630.

derek.john.evans

  • Jr. Member
  • **
  • Posts: 55
Re: cannot receive messages; udp server with lnet
« Reply #3 on: July 01, 2022, 01:56:37 am »
Why not just put 28?

prodingus

  • Jr. Member
  • **
  • Posts: 74
Re: cannot receive messages; udp server with lnet
« Reply #4 on: July 01, 2022, 02:01:32 am »
Stupid me, just 28 works! Still no received data from "server".
lazarus 1.6, FPC 3.0, SVN 51630.

derek.john.evans

  • Jr. Member
  • **
  • Posts: 55
Re: cannot receive messages; udp server with lnet
« Reply #5 on: July 01, 2022, 03:22:23 am »
The ludp example works fine. Your code fails here for a few reasons. The port number 28 returns Permission denied. I used 1234 with ludp and it worked.

Also, the example uses the callback OnReceive to handle listening events.

As a tip. Always start with a working example and then hack it to suit your requirements.

MarkMLl

  • Hero Member
  • *****
  • Posts: 4728
Re: cannot receive messages; udp server with lnet
« Reply #6 on: July 01, 2022, 09:19:49 am »
Stupid me, just 28 works! Still no received data from "server".

Look, if you'd told us in the first place what OS, version of the compiler etc. you'd got you'd have made it a damn sight easier for everybody.

You can't use ports <1024 (or maybe <=, can't remember) on a unix-like OS including Linux without having root privilege. Not sure whether there's a corresponding restriction on Windows etc.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

prodingus

  • Jr. Member
  • **
  • Posts: 74
Re: cannot receive messages; udp server with lnet
« Reply #7 on: July 01, 2022, 04:53:00 pm »
Sorry for the missing info: the testing is done on 2 win7 sp1 x64 lite vms, lazarus 1.6, FPC 3.0, SVN 51630.

Quote
Your code fails here for a few reasons. The port number 28 returns Permission denied. I used 1234 with ludp and it worked.

Before switching to lnet, I was testing with BlckSock (synapse?). I was still using port 28 on both vms and it I was sending and receiving just fine.

Quote
Also, the example uses the callback OnReceive to handle listening events.
I don't work with classes and methods... I don't know how to use it.
lazarus 1.6, FPC 3.0, SVN 51630.

prodingus

  • Jr. Member
  • **
  • Posts: 74
Re: cannot receive messages; udp server with lnet
« Reply #8 on: July 01, 2022, 04:56:46 pm »
Ps, changing port number, still no receive.
lazarus 1.6, FPC 3.0, SVN 51630.

Remy Lebeau

  • Hero Member
  • *****
  • Posts: 1129
    • Lebeau Software
Re: cannot receive messages; udp server with lnet
« Reply #9 on: July 01, 2022, 07:22:43 pm »
Code: Pascal  [Select][+][-]
  1. repeat begin
  2.   Sock.getmessage(tmp);
  3.   writeln(Sock.getmessage(tmp));
  4.  
  5.   sleep(100);
  6. end; until false;

Why are you calling getmessage() twice per loop iteration?  Get rid of the 1st one.  Or, use the OnReceive event, like Derek suggested.

You can't use ports <1024 (or maybe <=, can't remember) on a unix-like OS including Linux without having root privilege. Not sure whether there's a corresponding restriction on Windows etc.

There is no such restriction on Windows.
« Last Edit: July 01, 2022, 07:32:03 pm by Remy Lebeau »
Remy Lebeau
Lebeau Software - Owner, Developer
Internet Direct (Indy) - Admin, Developer (Support forum)

prodingus

  • Jr. Member
  • **
  • Posts: 74
Re: cannot receive messages; udp server with lnet
« Reply #10 on: July 02, 2022, 03:00:45 pm »
Quote
Why are you calling getmessage() twice per loop iteration?  Get rid of the 1st one.

I did try with one,  same result as before.

Quote
Or, use the OnReceive event, like Derek suggested.

Can someone help me on this? I need a straigthforward way (if possible) to receive udp data.
lazarus 1.6, FPC 3.0, SVN 51630.

derek.john.evans

  • Jr. Member
  • **
  • Posts: 55
Re: cannot receive messages; udp server with lnet
« Reply #11 on: July 02, 2022, 04:15:08 pm »
I don't work with classes and methods... I don't know how to use it.
Can someone help me on this? I need a straigthforward way (if possible) to receive udp data.

We can go around and around in circles for days. You cant blindly brute force an API to work the way you want. There are standard processes required to work though these problems. The first... Is to verify that the example is working.

1) Have you successfully compiled and tested the example? If yes...
2) Do you understand the example? If no, then play with the code and read the LNet classes until you do, then goto (2)
3) If yes, split the example into two separate projects for client/server.
4) If your hacking fails, return to step 2

It looks like you want the API to match your desired "style of coding" rather than accept the API must be used in a certain way.

Personally, I use Indy since I've been using that for almost 20 years. But, I can tell you, LNet is not a low Unix networking API.

Follow the example!
« Last Edit: July 02, 2022, 04:18:31 pm by derek.john.evans »

derek.john.evans

  • Jr. Member
  • **
  • Posts: 55
Re: cannot receive messages; udp server with lnet
« Reply #12 on: July 02, 2022, 04:26:54 pm »
One last thought. RE: I don't work with classes and methods... I don't know how to use it.

You don't have to use a OOP class libraries. I know lots of coders who refuse to use them for a number of reasons.

There is nothing wrong with going "old school". Here is C code for UDP client/servers.

https://www.cs.cmu.edu/afs/cs/academic/class/15213-f99/www/class26/

You can convert that to Pascal, or go with C. It doesn't matter. But, really, if you don't want learn Object Pascal, then why are you asking for help?

prodingus

  • Jr. Member
  • **
  • Posts: 74
Re: cannot receive messages; udp server with lnet
« Reply #13 on: July 02, 2022, 04:36:06 pm »
Quote
if you don't want learn Object Pascal, then why are you asking for help?

Is it wrong to use plain Pascal instead of Object Pascal?

As I created a simple loop that sends udp packets (and I receive them on the "server" side using the hercules utility), I need a simple loop that "gets" any pressent packets.
« Last Edit: July 02, 2022, 04:38:39 pm by prodingus »
lazarus 1.6, FPC 3.0, SVN 51630.

PascalDragon

  • Hero Member
  • *****
  • Posts: 4290
  • Compiler Developer
Re: cannot receive messages; udp server with lnet
« Reply #14 on: July 02, 2022, 04:38:05 pm »
Quote
if you don't want learn Object Pascal, then why are you asking for help?

Is it wrong to use plain Pascal instead of Object Pascal?

Considering that you're using lnet you are using Object Pascal. So if you want to use the components correctly you must use the mechanisms and concepts provided by Object Pascal (which includes event handlers).

 

TinyPortal © 2005-2018