[Lazarus] Sockets
dayat
dayat.aceh at gmail.com
Wed Jul 15 17:17:31 CEST 2009
Hello Marc,
Thanks for your reply. I am only use one units, and it is the Sockets unit.
The full code appear like:
{---------------------------------------------------------------------------}
program server;
uses
Sockets;
var
FromName: shortstring;
Buffer: string[255];
S: LongInt;
Sin, Sout: Text;
SAddr: TInetSockAddr;
procedure perror(const S:String);
begin
writeln(S,socketerror);
halt(100);
end;
begin
S:=Socket(AF_INET, SOCK_STREAM,0);
if socketerror<>0 then
perror('server: socket');
SAddr.sin_family:=AF_INET;
SAddr.sin_port:=htons(50000);
SAddr.sin_addr.s_addr:=0;
if not Bind(S, SAddr, sizeof(SAddr)) then
perror('server : bind : ');
if not Listen(S, 1) then
perror('server : listen : ');
writeln('Waiting for connect from client, run now sock_cli in an other tty');
if not Accept(S, FromName, Sin, Sout) then
perror('Server accept: '+FromName);
Reset(sin);
Rewrite(Sout);
WriteLn(Sout,'Message from server');
Flush(Sout);
while not EOF(sin) do begin
ReadLn(sin, buffer);
writeln('server : read : ', buffer);
end;
end.
{---------------------------------------------------------------}
I'm just copy this code from doc/rtl.pdf file in sockets units part.
I'm using freepascal 2.2.4
Regard
Hidayat
On 7/15/09, Marc Weustink <marc.weustink at cuperus.nl> wrote:
> dayat wrote:
>> Hi, I'm newbie in sockets programming.
>>
>> I have code like:
>>
>> if not Accept(S, FromName, Sin, Sout) then
>> perror('Server accept: '+FromName);
>>
>> The FromName variable is string. And when the Accept() function
>> executed I got the error like:
>> project1.lpr(31,28) Error: Call by var for arg no. 2 has to match
>> exactly: Got "ShortString" expected "sockaddr_in"
>
>
> Aahh... took me a while before I realized Accept has 5 different forms
> (defined in the unit sockets where the accept function is depricated)
>
> Is Sockets the only unit you use or do you use more units ?
>
> Do you use ansistrings ? (see {$H+} in the top of your code). Ifso,
> declare FromName as ShortString
>
> Marc
>
>
> --
> _______________________________________________
> Lazarus mailing list
> Lazarus at lists.lazarus.freepascal.org
> http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
>
More information about the Lazarus
mailing list