Socket Programming lazarus / 1-Linux ---------------------------------------------------------------------- thaimann · 2005-06-26 17:03 I have been playing around with socket programming with Lazarus.  I hjave used the simpleserver/simpleclient from the following web page: http://www.bastisoft.de/pascal/pasinet.html Now I can compile and run the simpoleserver example with fpc and it runs correctly. But if I run it as a thread, two things happen. 1.  It won't run unless I run it as root. 2.  When running as root, it won't accept any connecftions. Any clue as to why this doesn't work? My thread is defined as follows: Procedure TSockThread.Execute; const    ListenPort : Word = $AFFE;    MaxConn = 1; var    lSock, uSock : LongInt;    sAddr : TInetSockAddr;    Len : LongInt;    Line : String;    sin, sout : Text; begin    lSock := Socket(af_inet, sock_stream, 0);    if lSock = -1 then SockError('Socket: ');    with sAddr do    begin       Family := af_inet;       Port := htons(ListenPort);       Addr := 0;    end;    if not Bind(lSock, sAddr, sizeof(sAddr)) then SockError('Bind: ');    if not Listen(lSock, MaxConn) then SockError('Listen: ');    repeat       Say('Waiting for connections...');       Len := sizeof(sAddr);       uSock := Accept(lSock, sAddr, Len);       if uSock = -1 then SockError('Accept: ');       Say('Accepted connection from ' + AddrToStr(sAddr.Addr));       Sock2Text(uSock, sin, sout);       Reset(sin);       Rewrite(sout);       Writeln(sout, 'Welcome, stranger!');       while not eof(sin) do       begin          Readln(sin, Line);          if Line = 'close' then break;          Writeln(sout, Length(Line));       end;       Close(sin);       Close(sout);       Shutdown(uSock, 2);       Say('Connection closed.');    until False; End; ---------------------------------------------------------------------- Almindor · 2005-07-04 08:39 I don't know why it makes problems but I know that using write[ln] and textfiles as bufferes was buggy. Also fpc internaly uses winsock 1 in windows. I'd advise you to get winsock2 header and use recv/send. ---------------------------------------------------------------------- fatg · 2005-07-05 23:22 Or maybe try a higher-level implementation of sockets, like Synapse? ---------------------------------------------------------------------- Anonymous · 2005-07-27 15:25 I highly recommend Synapse, it totally rocks and has great support built in for SSL, super easy to use also. Quote from: "fatg"Or maybe try a higher-level implementation of sockets, like Synapse?