Hi,

You code not complete. You did not create the socket.

   socket := TWScoket.Create(   );


constructor TClient.Create;
begin
  inherited;
  (* This part crashes *)
  sock
  socket.OnDataAvailable := SocketDataAvailable;
  socket.OnSessionClosed := SocketSessionClosed;
end;

-----Original Message-----
From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]
Behalf Of Michael Preslar
Sent: Thursday, January 05, 2006 10:11 AM
To: twsocket@elists.org
Subject: [twsocket] Client and Server at same time?


Hello..

I'm working on a program that could be either a client and/or a server
at the same time. Well, wanting to work on it.

Going by the ICS examples, I've put together some code that should work.

I have a:

type TClient = class(TObject)
     Peer      : String;
     Socket : TWSocket;
     constructor Create;
     procedure SocketDataAvailable(Sender: TObject; Error: Word);
     procedure SocketSessionClosed(Sender: TObject; Error: Word);
   private
     buffer : ansistring;
   public
     AcceptForm : TForm;
     Reference  : Pointer;
     PortNum    : Integer;
     peername   : TSockAddrIn;
   end;


then in TClient.create I do

begin
   inherited;
   socket.OnDataAvailable := SocketDataAvailable;
   socket.OnSessionClosed := SocketSessionClosed;
end;

Which crashed the program. What's the proper way to do this?

Full source to an example program can be found at
http://www.mpcode.com/cliserv.zip (its d6 code, but should be fine with
anything that runs ICS and Delphi)
--
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to