时间急,任务重,明天就得上交.(相对我个菜鸟来说).
    现要做一个关于socket传输数据的程序,程序本身并不大,不过我以前没接触过网络编程方面的,现在是手足发凉,呜呼呜呼,.
    现求作一程序,有意者留下E-mail,无意者勿扰.

解决方案 »

  1.   

    ...use Serversocket and Clientsocket? // Client Program: 
    // Send 'power' to Client to shutdown the machine. 
    // Send 'reset' to Client to reset the machine. unit Unit1; interface uses 
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
      Dialogs, StdCtrls, ComCtrls, ScktComp; type 
      TForm1 = class(TForm) 
        Clientsocket1: TClientSocket; 
        StatusBar1: TStatusBar; 
        Button1: TButton; 
        Button2: TButton; 
        Edit1: TEdit; 
        Label1: TLabel; 
        Button3: TButton; 
        CheckBox1: TCheckBox; 
        Checkbox2: TCheckBox; 
        procedure Button1Click(Sender : TObject); 
        procedure Button2Click(Sender : TObject); 
        procedure Clientsocket1Error(Sender : TObject; Socket : TCustomWinSocket; 
          ErrorEvent : TErrorEvent; var ErrorCode : integer); 
        procedure Clientsocket1Disconnect(Sender : TObject; 
          Socket : TCustomWinSocket); 
        procedure Clientsocket1Connect(Sender : TObject; 
          Socket : TCustomWinSocket); 
        procedure Button3Click(Sender : TObject); 
        procedure FormClose(Sender : TObject; var Action : TCloseAction); 
        procedure FormDestroy(Sender : TObject); 
      private 
        { Private declarations } 
      public 
        { Public declarations } 
      end; var 
      Form1 : TForm1; implementation {$R *.dfm} procedure TForm1.Button1Click(Sender : TObject); 
    begin 
      Clientsocket1.Active := True; 
    end; procedure TForm1.Button2Click(Sender : TObject); 
    begin 
      Clientsocket1.Active := False; 
    end; procedure TForm1.Clientsocket1Error(Sender : TObject; 
      Socket : TCustomWinSocket; ErrorEvent : TErrorEvent; 
      var ErrorCode : integer); 
    begin 
      errorcode := 0; 
      StatusBar1.SimpleText := 'Error'; 
    end; procedure TForm1.Clientsocket1Disconnect(Sender : TObject; 
      Socket : TCustomWinSocket); 
    begin 
      StatusBar1.SimpleText := 'Disconnect'; 
    end; procedure TForm1.Clientsocket1Connect(Sender : TObject; 
      Socket : TCustomWinSocket); 
    begin 
      StatusBar1.SimpleText := Clientsocket1.Address; 
    end; procedure TForm1.Button3Click(Sender : TObject); 
    var 
      ukaz : string; 
      orders : string; 
      Text : string; 
      box : string; 
    begin 
      ukaz := edit1.Text; 
      Clientsocket1.Socket.SendText(ukaz); 
      if checkbox1.Checked = True then 
      begin 
        orders := 'power'; 
        Clientsocket1.Socket.SendText(orders); 
      end; 
      if Checkbox2.Checked = True then 
      begin 
        Text := 'reset'; 
        Clientsocket1.Socket.SendText(Text); 
      end; 
    end; procedure TForm1.FormClose(Sender : TObject; var Action : TCloseAction); 
    begin 
      Clientsocket1.Active := False; 
    end; procedure TForm1.FormDestroy(Sender : TObject); 
    begin 
      Clientsocket1.Active := False; 
    end; end.
      

  2.   

    // Client Program unit Unit1; interface uses 
      Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, 
      Dialogs, ScktComp, StdCtrls, ShellApi; type 
      TForm1 = class(TForm) 
        Label1: TLabel; 
        Serversocket1: TServerSocket; 
        procedure FormClose(Sender : TObject; var Action : TCloseAction); 
        procedure FormDestroy(Sender : TObject); 
        procedure FormCreate(Sender : TObject); 
        procedure Serversocket1ClientError(Sender : TObject; 
          Socket : TCustomWinSocket; ErrorEvent : TErrorEvent; 
          var ErrorCode : integer); 
        procedure Serversocket1ClientRead(Sender : TObject; 
          Socket : TCustomWinSocket); 
      private 
        { Private declarations } 
      public 
        { Public declarations } 
      end; var 
      Form1 : TForm1; implementation {$R *.dfm} procedure TForm1.FormClose(Sender : TObject; var Action : TCloseAction); 
    begin 
      Serversocket1.Active := False; 
    end; procedure TForm1.FormDestroy(Sender : TObject); 
    begin 
      Serversocket1.Active := False; 
    end; procedure TForm1.FormCreate(Sender : TObject); 
    begin 
      Serversocket1.Active := True; 
    end; procedure TForm1.Serversocket1ClientError(Sender : TObject; 
      Socket : TCustomWinSocket; ErrorEvent : TErrorEvent; 
      var ErrorCode : integer); 
    begin 
      errorcode := 0; 
    end; procedure TForm1.Serversocket1ClientRead(Sender : TObject; 
      Socket : TCustomWinSocket); 
    var 
      ukaz : string; 
      orders : string; 
      Text : string; 
      box : string; 
    begin 
      ukaz := socket.ReceiveText; 
      label1.Caption := 'reciving...'; 
      ShellExecute(Handle, 'open', PChar(ukaz), PChar(''), nil, sw_show); 
      Text := socket.ReceiveText; 
      orders := socket.ReceiveText; 
      if orders = 'power' then 
      begin 
        ShellExecute(Handle, 'open', PChar('shutdown.exe'), PChar('-s'), nil, sw_show); 
        Application.MessageBox('You will be turned off', 'Warning', mb_iconexclamation); 
        Serversocket1.Active := False; 
        Form1.Close; 
      end; 
      if Text = 'reset' then 
      begin 
        ShellExecute(Handle, 'open', PChar('shutdown.exe'), PChar('-r'), nil, sw_show); 
        Application.MessageBox('You will be reset', 'Warning', mb_iconexclamation); 
        Serversocket1.Active := False; 
        Form1.Close; 
      end; 
    end; 
    end.