Einzelnen Beitrag anzeigen

Marco Haffner
(Gast)

n/a Beiträge
 
#10

Re: Error 10049 kann nicht connecten

  Alt 9. Jul 2003, 23:02
Delphi-Quellcode:
procedure TForm1.ServerSocketClientConnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  StatusBar.Panels[0].Text := 'Server verbunden';
end;

procedure TForm1.ServerSocketClientDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  StatusBar.Panels[0].Text := 'Server getrennt';
end;

procedure TForm1.ServerSocketAccept(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  with ListBox.Items do
  begin
    Add('Client akzeptiert:');
    Add('> Host : ' + Socket.RemoteHost);
    Add('> Adresse: ' + Socket.RemoteAddress);
  end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  ServerSocket.Open;
  EditHostChange(nil);
end;

procedure TForm1.ButtonConnectClick(Sender: TObject);
begin
  with ClientSocket do
  begin
    Host := EditHost.Text;
    Open;
  end;
end;

procedure TForm1.EditHostChange(Sender: TObject);
begin
  ButtonConnect.Enabled := not (EditHost.Text = '') and not ClientSocket.Active;
end;

procedure TForm1.ClientSocketConnect(Sender: TObject;
  Socket: TCustomWinSocket);
var
  Text: string;
begin
  ButtonConnect.Enabled := False;
  ButtonDisconnect.Enabled := True;
  EditHost.Enabled := False;
  StatusBar.Panels[1].Text := 'Client verbunden';

  Text := Socket.LocalHost;
  Socket.SendBuf(PChar(Text)^, Length(Text));
end;

procedure TForm1.ClientSocketDisconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
  ButtonConnect.Enabled := True;
  ButtonDisconnect.Enabled := False;
  EditHost.Enabled := True;
  StatusBar.Panels[1].Text := 'Client getrennt';
end;

procedure TForm1.ButtonDisconnectClick(Sender: TObject);
begin
  ClientSocket.Close;
end;

procedure TForm1.ServerSocketClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
  RecText: string;
begin
  SetLength(RecText, Socket.ReceiveLength);
  Socket.ReceiveBuf(PChar(RecText)^, Socket.ReceiveLength);
  ShowMessage(RecText);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  ClientSocket.Close;
  ServerSocket.Close;
end;
  Mit Zitat antworten Zitat