Sign in Join

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

Mailing lists / fpc-pascal / 2002-08

Sockets

9 messages · 5 people · –

Reply by email Subscribe to this list Your subscription

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

Peter H.M. Brooks

I have read the previous discussion, last year, on the subject of sockets. I am familiar with sockets under UNIX.

What I need to do in the short term is quite simple. I want to set up a peer to peer UDP conversation between two machines, both of them windows 2000. Clearly it would be just as easy for one to be a UNIX box, once the protocol is working.

The problem I have is that I am using the simple socket example the previous discussion gave and I get a -1 from the connect. SocketError gives me no help as it returns a 0, suggesting it all worked.

Ultimately I would like to get sockets working for IPV6 between two cooperating processes - though actually this is one sub-goal to getting a proper conversation going with the SMTP port with MS Exchange tnef.

Has anybody got some working code that sets up an internet socket on one side, then exchanges messages (prefereably with UDP, though TCP is fine)? I am sure that this should be fairly simple, but the documentation is sparce in the extreme which makes it a little more of a challenge!

Peter

Reply by email

Thierry Cabuzel
to Peter H.M. Brooks

If someone have sothing like this I would be pleased too. I have already tried to do something like this and fall. The client connect to the server, send the first packet, close the connection, reopen another connection, and send another packet. At this point the server only receive garbage :-(

Earlier message 31 lines
-----Message d'origine----- De : la part de Peter H.M. Brooks Envoyé : samedi 17 août 2002 22:57 À : Objet : [fpc-pascal]Sockets I have read the previous discussion, last year, on the subject of sockets. I am familiar with sockets under UNIX. What I need to do in the short term is quite simple. I want to set up a peer to peer UDP conversation between two machines, both of them windows 2000. Clearly it would be just as easy for one to be a UNIX box, once the protocol is working. The problem I have is that I am using the simple socket example the previous discussion gave and I get a -1 from the connect. SocketError gives me no help as it returns a 0, suggesting it all worked. Ultimately I would like to get sockets working for IPV6 between two cooperating processes - though actually this is one sub-goal to getting a proper conversation going with the SMTP port with MS Exchange tnef. Has anybody got some working code that sets up an internet socket on one side, then exchanges messages (prefereably with UDP, though TCP is fine)? I am sure that this should be fairly simple, but the documentation is sparce in the extreme which makes it a little more of a challenge! Peter

Reply by email

Peter H.M. Brooks
to Thierry Cabuzel

----- Original Message -----
From: Thierry Cabuzel
To:
Sent: Sunday, August 18, 2002 12:19 AM
Subject: RE: [fpc-pascal]Sockets

If someone have sothing like this I would be pleased too. I have already tried to do something like this and fall. The client connect to the server, send the first packet, close the connection, reopen another connection, and send another packet. At this point the server only receive garbage :-(

Do you have some code and a log?

I am surprised, though that you close the connection. Surely, for the duration of the conversation, you should hold the connection open - if you are using TCP, that is. With UDP you would expect one packet per conversation and it shouldn't matter if you close the connection (in fact you don't have a connection end to end, only a local connection).

Actually, maybe that is your problem (though the code would be needed to know). With UDP you only send one packet and it is a connection less conversation - it is up to the higher levels to establish a re-try or other packet loss mechanism.

It would be good to hear from somebody who has had both a TCP and a UDP protocol working.

Peter

Reply by email

Unknown author
to Thierry Cabuzel: If someone have sothing like this I would be pleased too. I have already tried to do…

Hello

you wrote 5 lines
If someone have sothing like this I would be pleased too. I have already tried to do something like this and fall. The client connect to the server, send the first packet, close the connection, reopen another connection, and send another packet. At this point the server only receive garbage :-(

I have similar problem years ago :') Try this:
http://free.polbox.pl/s/szdowk/vsapass

S.Dowkontt

Reply by email

Peter H.M. Brooks
to Unknown author
Show quoted text 11 lines
On Sunday 18 August 2002 00:19, you wrote: > If someone have sothing like this I would be pleased too. I have > already tried to do something like this and fall. The client connect > to the server, send the first packet, close the connection, reopen > another connection, and send another packet. At this point the server > only receive garbage :-( I have similar problem years ago :') Try this: http://free.polbox.pl/s/szdowk/vsapass

I had a look at this one, but it only runs under linux. Setting up and using sockets in linux is easy - actually you don't even need to do it, simply have your code called by inetd and it will do all the socket work for you.

In windows, since its networking is such a mess, it is more difficult. Unfortunately I do need to get sockets working for windows 2000.

Peter

Reply by email

Thierry Cabuzel
to Peter H.M. Brooks: ----- Original Message ----- From: Thierry Cabuzel To: Sent: Sunday, August 18, 2002…

It is an old code. But it is very similar to BUG 1694. In my case, the client was not a VB program, but the apache module mod_lisp. This module open socket connection to another server to pass HTTP parameters from Apache to another server (A Freepascal Program in my case :-) ). I have done it in LISP and VB without any problem. I have tried with FreePascal but fail to do it :-(

!!! Warning !!! Crappy test code ahead :-)
---------------------------------------------------------------------------- ----
Uses Sockets;

Var
     lSock : LongInt;
     uSock : LongInt;
     sAddr : TInetSockAddr;
     lLen  : LongInt;
     sLine : String;
     SIn   : Text;
     SOut  : Text;
     AAA   : Boolean;
Procedure PError (Const S : String);
Begin
     Writeln (S, SocketError);
     Halt (100);
End;
Begin
     lSock:=Socket (AF_Inet, Sock_Stream, PF_Unspec);
     If SocketError0 Then PError ('Server : Socket : ');
     sAddr.Family:=AF_Inet;
     sAddr.Port  :=lo (3000) shl 8 or hi (3000);
     sAddr.Addr  :=(1 shl 24) or 127;
     If Not Bind (lSock, sAddr, SizeOf (sAddr)) Then PError ('Server : Bind
: ');
     If Not Listen (lSock, 1) Then PError ('Server : Listen : ');
     Repeat
          Writeln ('Accepting connection...');
          lLen :=SizeOf (sAddr);
          uSock:=Accept (lSock, sAddr, lLen);
          If SocketError0 Then PError ('Server : Accept : ');
          Writeln ('Connection accepted...');
          Sock2Text (USock, SIn, SOut); Write ('a');
          Reset (SIn); Write ('b');
          Rewrite (SOut); Write ('c');
          AAA:=False;
          While Not Eof (SIn) Do
          Begin
               ReadLn (SIn, sLine); write (sline, ';;');
               If AAA=True Then
               Begin
                    AAA:=False;
                    Writeln ('url = ', sLine);
               End;
               If sLine='url' Then AAA:=True;
               If sLine='end' Then Break;
          End;
          Write ('d');
          sLine:='<!DOCTYPE HTML PUBLIC "-//IETF//DTD
HTML//EN"><HTML><HEAD></HEAD><BODY><H1>mod_lisp 2.0b2</H1><P>This is a
constant html string sent by Apache + mod_lisp 2.0b2 + FreePascal +
Windows</P></BODY></HTML>';
          Writeln (SOut, 'Status');
          Writeln (SOut, '200 OK');
          Writeln (SOut, 'Content-Type');
          Writeln (SOut, 'text/html');
          Writeln (SOut, 'Content-Length');
          Writeln (SOut, Length (sLine)+2);
          Writeln (SOut, 'Keep-Socket');
          Writeln (SOut, '0');
          writeln (SOut, 'end');
          Writeln (SOut, sLine);
          Close (Sin);
          Close (SOut);
          ShutDown (uSock, 2);
     Until False;
End.
----------------------------------------------------------------------------
----
Earlier message 40 lines
-----Message d'origine----- De : la part de Peter H.M. Brooks Envoyé : dimanche 18 août 2002 00:31 À : Objet : Re: [fpc-pascal]Sockets ----- Original Message ----- From: Thierry Cabuzel To: Sent: Sunday, August 18, 2002 12:19 AM Subject: RE: [fpc-pascal]Sockets If someone have sothing like this I would be pleased too. I have already tried to do something like this and fall. The client connect to the server, send the first packet, close the connection, reopen another connection, and send another packet. At this point the server only receive garbage :-( Do you have some code and a log? I am surprised, though that you close the connection. Surely, for the duration of the conversation, you should hold the connection open - if you are using TCP, that is. With UDP you would expect one packet per conversation and it shouldn't matter if you close the connection (in fact you don't have a connection end to end, only a local connection). Actually, maybe that is your problem (though the code would be needed to know). With UDP you only send one packet and it is a connection less conversation - it is up to the higher levels to establish a re-try or other packet loss mechanism. It would be good to hear from somebody who has had both a TCP and a UDP protocol working. Peter

Reply by email

amorel
to Thierry Cabuzel

The source distribution tarball, I got it with the full archive, the one on the site(1.0.6), seems a bit broken. If I try to compile the compiler or ide or something(make ide etc) it always quits not being able to find an include file (for example:
syslinux.pp(25,2) Fatal: Can't open include file sysunixh.inc make[3]: *** [compunit.ppu] Error 1).
Do I miss something obvious, or do I use the wrong command parameters?

That particular include file is there, just in another directory, copying it to the directory it`s looking in doesn`t help too much as then it can`t find another include and so on(I bet).

Regards

Reply by email

Marco van de Voort
to amorel
Show quoted text 11 lines
The source distribution tarball, I got it with the full archive, the one on the site(1.0.6), seems a bit broken. If I try to compile the compiler or ide or something(make ide etc) it always quits not being able to find an include file (for example: syslinux.pp(25,2) Fatal: Can't open include file sysunixh.inc make[3]: *** [compunit.ppu] Error 1). Do I miss something obvious, or do I use the wrong command parameters? That particular include file is there, just in another directory, copying it to the directory it`s looking in doesn`t help too much as then it can`t find another include and so on(I bet).

Use OPT='-va' or -vt to see what actually happens (pipe to file, a lot of data)

What probably happens is that files found in the search path trick the compiler into recompile the RTL. This fails, because it is done from the wrong dir, and the include paths aren't set up properly.

With above parameters you can see which files trigger this. Look for phrases similar too "xxx is newer than yyy, recompiling", and the lines just above them.

Reply by email