Hi. Help please. This code

--server--

program serverdelphi;

{$APPTYPE CONSOLE}

uses
  sysutils,
  dateutils,
  OverbyteIcsWSockBuf,
  OverbyteIcsWSocket,
  OverbyteIcsWSocketS;

type
  { TWorkClass }

  TWorkClass = class
  public
    procedure StateChange(Sender: TObject; OldState, NewState : TSocketState);
    procedure SslWSocketServer1ClientConnect(Sender: TObject;
      Client: TWSocketClient; Error: Word);
    procedure SessionConnect(Sender: TObject; ErrCode: Word);
  end;

var
  socket: TWSocketServer;
  WorkClass: TWorkClass;
  dt: tdatetime;

{ TWorkClass }

procedure TWorkClass.StateChange(Sender: TObject; OldState,
  NewState: TSocketState);
begin
  write(' From ' );
  case OldState of
    wsInvalidState: write('wsInvalidState');
    wsOpened: write('wsOpened');
    wsBound: write('wsBound');
    wsConnecting: write('wsConnecting');
    wsSocksConnected: write('wsSocksConnected');
    wsConnected: write('wsConnected');
    wsAccepting: write('wsAccepting');
    wsListening: write('wsListening');
    wsClosed: write('wsClosed');
  end;
  write (' To ');
  case NewState of
    wsInvalidState: write('wsInvalidState');
    wsOpened: write('wsOpened');
    wsBound: write('wsBound');
    wsConnecting: write('wsConnecting');
    wsSocksConnected: write('wsSocksConnected');
    wsConnected: begin
                   write('wsConnected');
                   try
                     socket.SendLine('test');
                   except
                     on E:Exception do
                       writeln('Connect E.Message=' + E.Message);
                   end;
                 end;
    wsAccepting: write('wsAccepting');
    wsListening: write('wsListening');
    wsClosed: write('wsClosed');
  end;
  writeln;
end;

procedure TWorkClass.SessionConnect(Sender: TObject; ErrCode: Word);
begin
  Writeln('session connect');
end;

procedure TWorkClass.SslWSocketServer1ClientConnect(Sender: TObject;
  Client: TWSocketClient; Error: Word);
begin
  writeln('connect');
end;

begin
  WorkClass := TWorkClass.Create;
  socket := TWSocketServer.Create(nil);
  socket.OnClientConnect := WorkClass.SslWSocketServer1ClientConnect;
  socket.OnSessionConnected := WorkClass.SessionConnect;
  socket.OnChangeState := WorkClass.StateChange;
  socket.Port:= '27777';
  socket.Addr:= '127.0.0.1';
  socket.Listen;
  dt := Now;
  repeat
    sleep(1000);
  until MinutesBetween(Now, dt) > 1;
  WorkClass.Free;
  socket.free;
end.

--client--

program clientdelphi;

{$APPTYPE CONSOLE}

uses
  sysutils,
  dateutils,
  OverbyteIcsWSockBuf,
  OverbyteIcsWSocket,
  OverbyteIcsWSocketS;

type
  { TWorkClass }

  TWorkClass = class
  public
    procedure StateChange(Sender: TObject; OldState, NewState : TSocketState);
    procedure CliSocketSessionConnected(Sender: TObject; ErrCode: Word);
  end;

var
  socket: TWSocket;
  WorkClass: TWorkClass;
  dt: tdatetime;
{ TWorkClass }

procedure TWorkClass.StateChange(Sender: TObject; OldState,
  NewState: TSocketState);
begin
  write(' From ' );
  case OldState of
    wsInvalidState: write('wsInvalidState');
    wsOpened: write('wsOpened');
    wsBound: write('wsBound');
    wsConnecting: write('wsConnecting');
    wsSocksConnected: write('wsSocksConnected');
    wsConnected: write('wsConnected');
    wsAccepting: write('wsAccepting');
    wsListening: write('wsListening');
    wsClosed: write('wsClosed');
  end;
  write (' To ');
  case NewState of
    wsInvalidState: write('wsInvalidState');
    wsOpened: write('wsOpened');
    wsBound: write('wsBound');
    wsConnecting: write('wsConnecting');
    wsSocksConnected: write('wsSocksConnected');
    wsConnected: begin
                   write('wsConnected');
                   try
                     socket.SendLine('test');
                   except
                     on E:Exception do
                       writeln('Connect E.Message=' + E.Message);
                   end;
                 end;
    wsAccepting: write('wsAccepting');
    wsListening: write('wsListening');
    wsClosed: write('wsClosed');
  end;
  writeln;
end;

procedure TWorkClass.CliSocketSessionConnected(Sender: TObject; ErrCode: Word);
begin
  writeln('CliSocketSessionConnected');
end;

begin
  WorkClass := TWorkClass.Create;
  socket := TWSocket.Create(nil);
  socket.OnChangeState := WorkClass.StateChange;
  socket.OnSessionConnected := WorkClass.CliSocketSessionConnected;
  socket.Port:= '27777';
  socket.Addr:= '127.0.0.1';
  try
    socket.Connect;
  except
    on E:Exception do
      writeln('Connect E.Message=' + E.Message);
  end;

  dt := now;
  repeat
    sleep(1000);
  until (MinutesBetween(Now, dt) > 1);
  WorkClass.Free;
  socket.free;
end.

--
don`t connect between.
i view this text
--server--
 From wsClosed To wsBound
 From wsBound To wsListening
--client--
 From wsClosed To wsOpened
 From wsOpened To wsConnecting

 its all.

 Help please

  

-- 
Best regards,
 Alexey Voytsehovich                          mailto:iron...@gmail.com

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

Reply via email to