Page 1 of 1

How can I use TSocket connect to Server (TCP/IP) automatic?

Posted: Thu Dec 28, 2006 9:44 am
by dutch
Dear Antonio,

I try to connect SockCli.exe to SockServ.exe automatic when activate Main Window but It cannot connect.

Has it a way to connect server automatically (Without user activate manually)

Best regards,
Dutch

Code: Select all

function Main(cIPAdd)
   local oBar

   Default cIPAdd := '192.168.0.238'

   DEFINE WINDOW oWnd TITLE "Client socket "+cIPAdd

   DEFINE BUTTONBAR oBar OF oWnd _3D

//   DEFINE BUTTON OF oBar ACTION Client(cIPAdd) TOOLTIP "Connect"

   DEFINE BUTTON OF oBar ;
      ACTION oSocket:SendData( "MSG This is a test" ) ;
      TOOLTIP "Send data"

   DEFINE BUTTON OF oBar ;
      ACTION SendFile() TOOLTIP "Send file"

   ACTIVATE WINDOW oWnd ;
       ON PAINT (Client(cIPAdd))

return nil

//---------------------------//
function Client(cIPAdd)

   oSocket = TSocket():New( 2000 )

   oSocket:bRead    = { | oSocket | MsgInfo( oSocket:GetData() ) }

   // Never use a MsgInfo() here because it hangs Windows!!!
   oSocket:bConnect = { || oWnd:SetText( "Connected!" ) }

   oSocket:bClose   = { || MsgInfo( "Server has closed!" ) }

   oSocket:Connect( cIPAdd ) // use the server IP address here

return nil

Re: How can I use TSocket connect to Server (TCP/IP) automat

Posted: Thu Dec 28, 2006 1:12 pm
by Enrico Maria Giordano
dutch wrote:

Code: Select all

   ACTIVATE WINDOW oWnd ;
       ON PAINT (Client(cIPAdd))
This is not right. Replace it with

Code: Select all

   ACTIVATE WINDOW oWnd ;
       ON INIT (Client(cIPAdd))
EMG

Posted: Fri Dec 29, 2006 5:54 am
by dutch
Thanks Enrico,

It works well.

Best regards,
Dutch