Board index » delphi » FPC Socket debuging

FPC Socket debuging

While the developers are taking a look at the 'feature' I discovered in FPC
1.02, I was wondering how can I debug a win32 socket program.  This line bombs
out every time:

TestSocket:=Socket (AF_INET,SOCK_STREAM,PF_INET);

I've verified the constants are there (2, 1, and 2 respectively), and the code
does not crash but it returns a 10043 in socketerror.  Other combinations of
constants (AF_INET6 btw is not defined like it shows in the docs) also do not
work, mainly giving other errors.  I know the 10043 is a Protocol not
supported - but I'm am using tcp/ip right now to write this!  I don't know how
to get the darn things to talk to eachother.  Does the TCP/IP protocol have to
be defined in a specific way on my machine?  Does the fact that I have a
static ip address have anything to do with it?

 

Re:FPC Socket debuging


Hi,

Quote
eada...@ford.com wrote:
> While the developers are taking a look at the 'feature' I discovered in FPC
> 1.02, I was wondering how can I debug a win32 socket program.  This line bombs
> out every time:

> TestSocket:=Socket (AF_INET,SOCK_STREAM,PF_INET);

> I've verified the constants are there (2, 1, and 2 respectively), and the code
> does not crash but it returns a 10043 in socketerror.

The question is: what is the return value? Is it -1? If not, SocketError
is irrelevant. (I hope I'm not asking you a stupid question here.)

Quote
> Does the TCP/IP protocol have to
> be defined in a specific way on my machine?  Does the fact that I have a
> static ip address have anything to do with it?

Not really. Should work out of the box if you have a Winsock DLL at
hand, AFAIK.

 - Sebastian

Re:FPC Socket debuging


Quote
Sebastian Koppehel wrote:
> The question is: what is the return value? Is it -1? If not, SocketError
> is irrelevant. (I hope I'm not asking you a stupid question here.)

> > Does the TCP/IP protocol have to
> > be defined in a specific way on my machine?  Does the fact that I have a
> > static ip address have anything to do with it?

> Not really. Should work out of the box if you have a Winsock DLL at
> hand, AFAIK.

>  - Sebastian

Sure, it's -1.  

Here's my code:
Program Client;

    {
      Program to test Sockets unit by Michael van Canneyt and Peter Vreman
      Client Version, First Run sock_svr to let it create a socket and then
      sock_cli to connect to that socket

      November 10, 2000:  Modifications by Eric Adams to test TCP/IP
      for OTMA IMS Connection.
    }

    uses Sockets,Windows;

{  ******* this code commented out until bug fix  *******
    Type
      BEC_Single_Error = record
         E : integer;
         M : string [80];
      end;

    Const
      BEC_Err_Msgs: array [0..2] of BEC_Single_Error =
       ((E : WinSock.WSABASEERR; M : '[0] No Error'),
        (E : WinSock.WSAEINTR;   M : '[10004] Interupted System Call'),
        (E : WinSock.WSAEBADF;   M : '[10009] Bad File Number'));
   ******************************************************}

    Var
      Saddr      : TINETSOCKADDR;
      Buffer     : string [255];
      TestSocket : Longint;
      Sin,Sout   : Text;
      i          : integer;

    procedure PError(const DispText : string);
    begin
      writeln('**************************');
      writeln('An error has been detected');
      writeln(DispText,SocketError);
      writeln('TestSocket = ',TestSocket);
      writeln('Saddr.family = ', Saddr.family);
      writeln('Saddr.port = ', Saddr.port);
      writeln('Saddr.addr = ', Saddr.addr);
        writeln('');
        writeln('CONSTANTS:');
        writeln('AF_INET = ', AF_INET, '  PF_INET = ', PF_INET);
        writeln('SOCK_STREAM = ', SOCK_STREAM);
      halt(100);
    end;

    BEGIN
      writeln('');
      writeln('Client socket test program');
      writeln('--------------------------');
      TestSocket:=Socket (AF_INET,SOCK_STREAM,PF_INET);
      if SocketError<>0 then
       Perror('Client : Socket : ');
      Saddr.family:=1;
      Saddr.port:=3001;
      Saddr.addr:=((1 shl 24) or (0 shl 16) or (0 shl 8) or 127);
      if not Connect (TestSocket,SAddr,Sin,Sout) then
       PError('Client : Connect : ');
      Reset(Sin);
      ReWrite(Sout);
      Buffer:='This is a textstring sent by the Client.';
      for i:=1 to 5 do
       Writeln(Sout,Buffer);
      Flush(Sout);
      Readln(SIn,Buffer);
      WriteLn(Buffer);
      Close(sout);
    END.

Here's my output:

Client socket test program
--------------------------
**************************
An error has been detected
Client : Socket : 10043
TestSocket = -1
Saddr.family = 0
Saddr.port = 0
Saddr.addr = 0

CONSTANTS:
AF_INET = 2  PF_INET = 2
SOCK_STREAM = 1

I have the wsock32.dll mentioned in the winsock.pp unit under the
windows/system directory, and it's version is 4.00.1111.

Could someone else with 1.02 try to compile and run this?  thanks...

Re:FPC Socket debuging


Hi,

Quote
eada...@ford.com wrote:
> Sebastian Koppehel wrote:
>> The question is: what is the return value? Is it -1? If not, SocketError
>> is irrelevant. (I hope I'm not asking you a stupid question here.)

> Sure, it's -1.  

Whoa, sorry. I didn't see that you specified PF_INET as protocol. That
is wrong: PF_INET is a replacement for AF_INET, the protocol parameter
is there to support different protocols inside a specific protocol
family (such as AF/PF_INET). These are the possible values (from my
/etc/protocols):

ip      0       IP      # internet protocol, pseudo protocol number
icmp    1       ICMP    # internet control message protocol
igmp    2       IGMP    # internet group multicast protocol
ggp     3       GGP     # gateway-gateway protocol
tcp     6       TCP     # transmission control protocol
pup     12      PUP     # PARC universal packet protocol
udp     17      UDP     # user datagram protocol
idp     22      IDP     # WhatsThis?
raw     255     RAW     # RAW IP interface

You'll normally want to choose 0.

 - Sebastian

Re:FPC Socket debuging


Quote
Sebastian Koppehel wrote:

> Whoa, sorry. I didn't see that you specified PF_INET as protocol. That
> is wrong: PF_INET is a replacement for AF_INET, the protocol parameter
> is there to support different protocols inside a specific protocol
> family (such as AF/PF_INET). These are the possible values (from my
> /etc/protocols):

> ip      0       IP      # internet protocol, pseudo protocol number
> icmp    1       ICMP    # internet control message protocol
> igmp    2       IGMP    # internet group multicast protocol
> ggp     3       GGP     # gateway-gateway protocol
> tcp     6       TCP     # transmission control protocol
> pup     12      PUP     # PARC universal packet protocol
> udp     17      UDP     # user datagram protocol
> idp     22      IDP     # WhatsThis?
> raw     255     RAW     # RAW IP interface

> You'll normally want to choose 0.

>  - Sebastian

Ok, I've gotten past the Testing Socket phase! Woohoo - progress!  Now I'm
here:
--------------------------
Client socket test program
--------------------------
****************************************
*** An error has been detected while
*** Connecting Socket
**** Socket Error = 10047
**** TestSocket   = 6
**** Saddr.family = 1
**** Saddr.port   = 3001
**** Saddr.addr   = 2451323667
****************************************

I get this when I use IP (0) or TCP (6).  Some of the others (RAW and UDP)
return 10043 again, but that doesn't surprise me.  10047 is address family not
supported by protocol family - that does surprise me.

Here's the modified code again:

Program Client;

    {
      Program to test Sockets unit by Michael van Canneyt and Peter Vreman
      Client Version, First Run sock_svr to let it create a socket and then
      sock_cli to connect to that socket

      November 20, 2000:  Modifications by Eric Adams to test TCP/IP
      for OTMA IMS Connection.  Windows 95 version with IE 5 installed.
    }

    uses Sockets,Windows;

    Const
     {**** <- Socket protocols ******************************************}
      IP     = 0;    {IP      # internet protocol, pseudo protocol number}
      ICMP   = 1;    {ICMP    # internet control message protocol}
      IGMP   = 2;    {IGMP    # internet group multicast protocol}
      GGP    = 3;    {GGP     # gateway-gateway protocol}
      TCP    = 6;    {TCP     # transmission control protocol}
      PUP    = 12;   {PUP     # PARC universal packet protocol}
      UDP    = 17;   {UDP     # user datagram protocol}
      IDP    = 22;   {IDP     # WhatsThis?}
      RAW    = 255;  {RAW     # RAW IP interface}

    Var
      Saddr      : TINETSOCKADDR;
      Buffer     : string [255];
      TestSocket : Longint;
      Sin,Sout   : Text;
      i          : integer;

    procedure PError(const Phase : string);
    begin
      writeln('****************************************');
      writeln('*** An error has been detected while    ');
      writeln('*** ', Phase);
      writeln('**** Socket Error = ', SocketError);
      writeln('**** TestSocket   = ', TestSocket);
      writeln('**** Saddr.family = ', Saddr.family);
      writeln('**** Saddr.port   = ', Saddr.port);
      writeln('**** Saddr.addr   = ', Saddr.addr);
      writeln('****************************************');
      halt(100);
    end;

    BEGIN
      writeln('');
      writeln('--------------------------');
      writeln('Client socket test program');
      writeln('--------------------------');
      TestSocket:=Socket (AF_INET,SOCK_STREAM,IP);
      if SocketError<>0 then
       Perror('Testing Socket ');
      Saddr.family:=1;
      Saddr.port:=3456;
      Saddr.addr:=((123 shl 24) or (45 shl 16) or (67 shl 8) or 89);
      if not Connect (TestSocket,SAddr,Sin,Sout) then
       PError('Connecting Socket ');
      Reset(Sin);
      ReWrite(Sout);
      Buffer:='This is a textstring sent by the Client.';
      for i:=1 to 5 do
       Writeln(Sout,Buffer);
      Flush(Sout);
      Readln(SIn,Buffer);
      WriteLn(Buffer);
      Close(sout);
    END.

Anyone else with winblows 95 and IE5.0 want to try and compile this?  Using
FPC 1.02, compiling from IDE, etc etc etc

Other Threads