Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2009-07

Sockets

5 messages · 2 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

dayat

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"

I get the example code in doc\rtl.dpf Sockets unit. How to fix this error, what the wrongs.

I have other questions, can lazarus install Indy components for Linux and WinCE targets.

Thank you for your help
regards
Hidayat

Reply by email

Marc Weustink
to dayat
dayat wrote 11 lines
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

Reply by email

dayat
to Marc Weustink

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 socketerror0 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

Marc Weustink wrote 31 lines
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 http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email

dayat
to Marc Weustink

March,

There are other ways to send the data through the network with freepascal. Ever you use lnet or indy in lazarus? Can we use this component to send data over network.

Regards,
Hidayat

Marc Weustink wrote 17 lines
dayat wrote: > Hello Marc, > > Thanks for your reply. I am only use one units, and it is the Sockets > unit. I would expect that the rtl example would work. Marc -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

Reply by email