[fpc-pascal]socket not ready help

J. Eduardo Garcia Torres enzo at compunet.net.co
Mon Jan 21 18:13:47 CET 2002


Hello list.

been trying to do a conexion by socket without success,

I send the code that myself, 
that has two errors of compilation to see if they help me to resolve it,
The errors are in the lines 39 and 44.

I expect thanks they help myself

thanks

-- 
enzo
J. Eduardo Garcia T.
icq:  69885612
Messenger : jegarto at hotmail.com
Current Proyect : gcafe - http://gcafe.es.gnome.org
web site:  www.geocities.com/netenzo
tel: +57 4 4150570
Medellin - Colombia - Sur America

-------------- next part --------------
Program sock2;
uses Sockets;

type
    UInt32 = DWord;
    UInt16 = Word;
const
    INVALID_SOCKET = -1; // dunno if this is already defined by Unices
var
    hoststring : String;{  your "192.168.1.1" }
    sock_fd : Longint; { socket (file) handle }
   // he : PHostEnt; {  host entry }
    port : UInt16; {  port, e.g. 3490 }
    their_addr : TInetSockAddr; {  target address }
    aux : longint;

begin

port := 3490;
 hoststring := '192.168.1.1';
{ he := gethostbyname(PChar(hoststring));
 if he = nil then
  sockshutdown('gethostbyname()');}

{
   prints given error message+last error number, closes socket if open
   and exits program
}
 Writeln('Retrieving socket....');
 sock_fd := Socket(AF_INET, SOCK_STREAM, 0);
 if (sock_fd = INVALID_SOCKET) then
 // sockshutdown('socket()');
 writeln('Invalid socket');

 fillchar(their_addr, sizeof(their_addr), 0);
 with their_addr do begin
  family := AF_INET;
  port := port;
   addr := Uint32(hoststring); 
 end;

 Writeln('Connecting to socket....');
 
 if (connect(sock_fd, their_addr, sizeof(their_addr)) <> -1) then
  begin
   writeln('Not connected to socket');
  end
 else
  begin
   writeln('Connected to socket');
   shutdown(sock_fd,2);
  end

end.




More information about the fpc-pascal mailing list