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

Post Reply
User avatar
dutch
Posts: 1395
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

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

Post 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
User avatar
Enrico Maria Giordano
Posts: 7355
Joined: Thu Oct 06, 2005 8:17 pm
Location: Roma - Italia
Contact:

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

Post 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
User avatar
dutch
Posts: 1395
Joined: Fri Oct 07, 2005 5:56 pm
Location: Thailand

Post by dutch »

Thanks Enrico,

It works well.

Best regards,
Dutch
Post Reply