Recent

Author Topic: fpConnect always returns 0  (Read 4049 times)

Aidex

  • Jr. Member
  • **
  • Posts: 82
fpConnect always returns 0
« on: January 24, 2019, 07:52:55 pm »
Hi! I try to connect to a server via socket and fpConnect().
But fpConnect() always results zero.
In case of an error, fpConnect should return -1, but it is zero. And zero is not a valid handle. SocketError is also zero.
I'm using Lazarus 1.8.4 on Windows 7 64.
Does anyone know any advice? Thank you!

uses sockets, resolve;

var
  ip4: resolve.THostAddr;
  Port: Word;
  addr: SockAddr;
  SocketHandle, ConnHandle: LongInt;

begin
  [ ... defining ip4 and Port ... ]

  SocketHandle := fpSocket(AF_INET,SOCK_STREAM,0);
  if SocketHandle=-1 then Exit(false);

  initialize(addr);
  addr.sin_family := AF_INET;
  addr.sin_port := htons(Port);
  addr.sin_addr.s_addr := htonl(ip4.s_addr);

  ConnHandle := fpConnect(SocketHandle,@addr,SizeOf(addr));
  ...

=> ConnHandle==0 and SocketError==0

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: fpConnect always returns 0
« Reply #1 on: January 24, 2019, 08:33:35 pm »
"The fpConnect function returns zero if the call was successfull, -1 in case of error."

Aidex

  • Jr. Member
  • **
  • Posts: 82
Re: fpConnect always returns 0
« Reply #2 on: January 25, 2019, 12:18:03 am »
My best thanks, I'm very embarrassed. I had convinced myself that fpConnect would return a new handle, just like fpAccept.
But instead I just have to continue using the SocketHandle. So simple. Now it works. Thanks a lot!

 

TinyPortal © 2005-2018