Newsgroup: it.comp.lang.delphi
Titolo: TClientSocket ?

Hello, there.
I'm beginner in Delphi.
I want to make a TCP Client  with delphi ,
that client  will try to connect to same serveral  TCP server processor
that's running on another machine with thire IP Address.
so , after connecting to server,
the client first send message , and then recevie simple message from server.
( server processor is java application).
after right that,java server close the socket.
                    ============== here is part of java code ===============
                        System.our.println ("first , read  line from client
" );
                        String line = in.readLine() ;
                        System.out.println("Message from Client
\""+line+"\"");
                        // second server send "OK"
                        out.println("OK");
                        if (out.checkError())
                                throw new IOException("Error while sending
OK");
                         }
                     //   close input , output streams
                       in.close();
                       out.close();
                =======================================================
the delphi client I want to make have to send message to server server
every 10 minutes.
to do this, I made Timer that's invoked every 10 minutes.
Clould someone take a look my Delpi code.
============================================================================
========
////this timer will be called every 10 minutes  to make ClientSocket as
number of server.
procedure TForm1.Timer1Timer(Sender: TObject);
var
   loopIndex : integer;
   ClientSocketArray : array of TClientSocket;
begin
    ///let's suppose,there are 3 server that we are goint to connect.
    // I'll make 3 TClientSocket.
     setLength ( ClientSocketArray , 3 );
     ///and IP Address for them.
    /// ipAddress[0] = '192.168.1.1'
    ///ipAddress[2] = '192.168.1.2'
    ///ipAddress[3] = '192.168.1.3'
     for  loopIndex := 2  downto 0 do
     begin
         if ClientSocketArray[loopIndex].Active then
ClientSocketArray[loopIndex].Active := False;
         ClientSocketArray[loopIndex] := TClientSocket.Create ( self );
         ClientSocketArray[loopIndex].OnConnect := ClientSocketConnect;
         ClientSocketArray[loopIndex].OnDisConnect :=
ClientSocketDisConnect;
         ClientSocketArray[loopIndex].OnRead := ClientSocketRead;
         ClientSocketArray[loopIndex].Host := ipAddress[loopIndex]
         ClientSocketArray[loopIndex].port :=  55555;
         ClientSocketArray[loopIndex].Active := True;
     end;
end;
procedure TForm1.ClientSocketDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
//
end;
procedure TForm1.ClientSocketRead(Sender: TObject;
  Socket: TCustomWinSocket);
begin
 eIPAddress.text := ( Socket.ReceiveText );
 ClientSocket.close;
end;
procedure TForm1.ClientSocketError(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
     ErrorCode := 0;
end;
procedure TForm1.ClientSocketConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
    ClientSocket.socket.sendText ( 'Hello server '  + #13 );
end;
end.
============================================================================
above my code did not work correctly, after connecting to first server, it
stop processing.
and rest part of code
(ClientSocketConnect,ClientSocketError,ClientSocketRead,ClientSocketDisconne
ct ) is OK as it is?
in my case where should I free ClientSocket[]
I'd like to thank you for telling me that what's wrong with code.
or are there some code example that i can reference it in my case.
could someone give an idea for implement that.
thank for your time.
hava a day.

    Hi, I have done a chat that use the opposite client/server structure
(Server with Delphi and Client with Java). The problem you have is that
Delphi's Socket did not send the Carriage Return character <cr> when you use
the function SendText. So the Java Server could not read the message with
the Stream function "readLine" because this one looks for a <cr> character
to detect the end of a line and th system hang up.
    I solve this prblem using a personalized protocol for sending message
(in my case the character "@" ended my text ) and I modified the Java
structure of reading using a function that read character by character
within a loop; when it found the special character, it outputs the string.
    I hope you could solve this problem....
    P.S. Delphi has not a Garbage COllector so you have to deallocate the
Socket object after use, with the function "Free".
--
_________________________________
Gian Luca Dalla Torre
E - Mail: 
gianluca....@casteo.net
_________________________________