Re: [fpc-pascal] SOLVED fpSelect fails with UDP sockets?

2016-04-03 Thread Mark Morgan Lloyd

wkitt...@windstream.net wrote:

NOTE: i've not done any research to see what dadr.sin_addr.s_bytes is 
but i assume that it is an array of bytes to contain each of the IP 
address parts...


It's usually an untagged variant record so you can also do something like

target.s_addr:= HToNL($7F01);

Just /don't/ assume you can do maths with it.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] SOLVED fpSelect fails with UDP sockets?

2016-04-03 Thread wkitty42

On 04/03/2016 12:32 PM, Klaus Hartnegg wrote:

   dadr.sin_family := AF_INET;
   dadr.sin_addr.s_bytes[1] := 127;
   dadr.sin_addr.s_bytes[2] := 0;
   dadr.sin_addr.s_bytes[2] := 0;
   dadr.sin_addr.s_bytes[2] := 1;


shouldn't this be

  dadr.sin_addr.s_bytes[1] := 127;
  dadr.sin_addr.s_bytes[2] := 0;
  dadr.sin_addr.s_bytes[3] := 0;
  dadr.sin_addr.s_bytes[4] := 1;


NOTE: i've not done any research to see what dadr.sin_addr.s_bytes is but i 
assume that it is an array of bytes to contain each of the IP address parts...


--
 NOTE: No off-list assistance is given without prior approval.
   *Please keep mailing list traffic on the list* unless
   private contact is specifically requested and granted.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] SOLVED fpSelect fails with UDP sockets?

2016-04-03 Thread Klaus Hartnegg

Am 03.04.2016 um 18:32 schrieb Klaus Hartnegg:

   dadr.sin_addr.s_bytes[1] := 127;
   dadr.sin_addr.s_bytes[2] := 0;
   dadr.sin_addr.s_bytes[2] := 0;
   dadr.sin_addr.s_bytes[2] := 1;


The array index numbers are of course garbage (from incomplete 
copy editing), but somehow it worked nevertheless.


Should have been
  dadr.sin_addr.s_bytes[1] := 127;
  dadr.sin_addr.s_bytes[2] := 0;
  dadr.sin_addr.s_bytes[3] := 0;
  dadr.sin_addr.s_bytes[4] := 1;

Loopback appears to catch the whole loopback network, not just that 
single address.

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] SOLVED fpSelect fails with UDP sockets?

2016-04-03 Thread Klaus Hartnegg

It works with
  rc := fpSelect (sock+1,@FDS,nil,nil,5000);

I did not understand the description of the first argument in the docs, 
so I used the value from the sample, this was not a good idea.



For reference here is the source that works:

Uses
  UnixType, BaseUnix, Sockets;

procedure abort (reason:string);
begin
  writeln (reason);
  halt;
end;

var
  sock: cint;
  ladr : SockAddr;
  radr : SockAddr;
  adrlen: tSockLen;
  msg : string[255];
  FDS : Tfdset;
  rc  : cint;

begin
  sock := fpSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if sock = -1 then
 abort ('Error from fpSocket');

  ladr.sin_family  := AF_INET;
  ladr.sin_addr.s_addr := INADDR_ANY;
  ladr.sin_port:= htons(2000);
  rc := fpBind (sock, @ladr, sizeof(ladr));
  if rc <> 0 then
 abort ('Error from fpBind');

  adrlen := sizeof(radr);

  Fpfd_zero (FDS);
  FpFd_set (sock,FDS);
  rc := fpSelect (sock+1,@FDS,nil,nil,5000);
  writeln (rc);
  if rc = -1 then
 abort ('Error from fpSelect');
  if rc = 0 then
 abort ('timeout');

  rc := fpRecvFrom (sock, @msg[1], 255, 0 {flags}, @radr, @adrlen);
  if rc = -1 then
 abort ('Error from FpRecv');

  if rc > 255 then
 rc := 255;
  msg[0] := chr(rc);
  writeln (msg);
end.



And this is the sender:

Uses
  UnixType, BaseUnix, Sockets;

procedure abort (reason:string);
begin
  writeln (reason);
  halt;
end;

var
  sock: cint;
  sadr: {TInet}SockAddr;
  dadr: {TInet}SockAddr;
  adrlen: tSockLen;
  msg : string;
  rc  : cint;

begin
  sock := fpSocket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if sock = -1 then
 abort ('Error from fpSocket');

  sadr.sin_family  := AF_INET;
  sadr.sin_addr.s_addr := INADDR_ANY;
  sadr.sin_port:= 0; { auto-select }
  rc := fpBind (sock, @sadr, sizeof(sadr));
  if rc <> 0 then
 abort ('Error from fpBind');

  dadr.sin_family := AF_INET;
  dadr.sin_addr.s_bytes[1] := 127;
  dadr.sin_addr.s_bytes[2] := 0;
  dadr.sin_addr.s_bytes[2] := 0;
  dadr.sin_addr.s_bytes[2] := 1;
  dadr.sin_port   := htons(2000);
  adrlen := sizeof(dadr);

  msg := 'hello, world!';

  rc := fpSendTo (sock, @msg[1], length(msg), 0 {flags}, @dadr, adrlen);
  if rc = length(msg) then
 writeln ('ok');
end.
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


Re: [fpc-pascal] Postgresql interface bronken for Raspberry pi model 1b

2016-04-03 Thread Björn Lundin
On 2016-04-02 20:29, Bo Berglund wrote:
> On Mon, 28 Mar 2016 15:30:36 +0200, Björn Lundin
>  wrote:
> 
>> That speaks for trying to compile 3.0.0.
>> The pi is on wheezy, so there is no .deb package
>> for it.
> 
> I made a script for installing FPV 3.0.0 and Lazarus 1.6 release on an
> RPi.
> http://blog.boberglund.com/install_laz_pi.sh
> 
> You can have a look at it and strip off Lazarus if you like.
> It is not very difficult to build FPC from sources really...
> One caveat with wheezy and some Pi versions is that you should up swap
> to 1000 to not get caught in the linker.
> Swap expansion is found in sudo raspi-config.


Yes, I saw that link somewhere else.
I got 2 pi:s, one original B with 256 mb and one later B model with 512
mb RAM.

I downloaded and ran it 'as is'. The pi:s do have 1Bb each of swap, but
both froze during compilation. Both are on rasbian wheezy.

I'll strip away lazarus as you say and try again.

If I don't get it to work, I'll look into cross compiling from win32 to
the pi


--
Björn
___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal

Re: [fpc-pascal] Write Applet with FPC JVM

2016-04-03 Thread Ingemar Ragnemalm



Message: 1
Date: Sat, 2 Apr 2016 03:39:41 -0700 (MST)
From: leledumbo 
To: fpc-pascal@lists.freepascal.org
Subject: Re: [fpc-pascal] Write Applet with FPC JVM
Message-ID: <1459593581645-5724733.p...@n5.nabble.com>
Content-Type: text/plain; charset=us-ascii


It compiles with both Java and FPC, but the FPC version doesn't run.

Works fine here:
fpc-helloworld-applet.png



Any ideas? Any obvious mistakes of mine?

I change your program to a unit, though I don't think that matters as long
as HelloWorldApplet.class is generated. Then I modify your applet tag by
removing archive attribute as it's not in a .jar but a standalone .class.
That's it.


Great! I tried and indeed, compiling a unit did it! Editing the HTML 
file didn't seem to matter though.



/Ingemar

___
fpc-pascal maillist  -  fpc-pascal@lists.freepascal.org
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal