[fpc-pascal]FPC Client with Sockets unit
Sir_Ty
sir_ty at bellsouth.net
Sun Dec 17 20:29:13 CET 2000
On a Windows 95 box, FPC 1.02, etc. I have modified the example source
code from the Documentation for the sockets unit (with a little help
from the comp.lang.pascal.misc newsgroup). However I continue to
receive a 10047 error, which is an 'Address family not supported by
protocol family' error. I've tried multiple combinations of IP (0) and
TCP (6) for both the TestSocket protocol and SAddr.family variables but
I continue to receive this error.
The error occurs on this line:
if not Connect (TestSocket,SAddr,Sin,Sout) then
Here is the complete source 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 20, 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'));
******************************************************}
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;
{ Return a longint which is an IP address in network byte order }
function IpNetOrder(a,b,c,d: byte): longint;
begin
IpNetOrder := ((d shl 24) or (c shl 16) or (b shl 8) or a)
end; {of IpNetOrder}
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 := TCP;
Saddr.port := 3001;
SAddr.addr := IpNetOrder(59,21,2,145);
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.
Another question - does the port value have to be in network order? (It
doesn't seem to make a difference on my end if it is...)
More information about the fpc-pascal
mailing list