Delphi implements a simple P2P chat program Show UntClient.pas Source code
Return
Download Delphi implements a simple P2P chat program:
download UntClient.pas Source code
- Download Delphi implements a simple P2P chat program Source code - Type:.pas
- unit UntClient;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, StdCtrls, IdBaseComponent, IdComponent, IdUDPBase, IdUDPClient,
- ScktComp, ExtCtrls;
- type
- TFrmClient = class(TForm)
- ClientSocket: TClientSocket;
- gb1: TGroupBox;
- gb2: TGroupBox;
- MemReadMsg: TMemo;
- btnSend: TButton;
- gb3: TGroupBox;
- MemSendMsg: TMemo;
- Connet: TButton;
- GroupBox1: TGroupBox;
- LeSrvName: TLabeledEdit;
- LeSrvPort: TLabeledEdit;
- procedure ConnetClick(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure LeSrvPortKeyPress(Sender: TObject; var Key: Char);
- procedure LeSrvNameKeyPress(Sender: TObject; var Key: Char);
- procedure ClientSocketRead(Sender: TObject; Socket: TCustomWinSocket);
- procedure btnSendClick(Sender: TObject);
- private
- { Private declarations }
- public
- { Public declarations }
- end;
- var
- FrmClient: TFrmClient;
- implementation
- {$R *.dfm}
- procedure TFrmClient.ConnetClick(Sender: TObject);
- begin
- Try
- if Trim(LeSrvName.Text )='' then
- begin
- MessageDlg('请输入服务器IP地址或机器名称!',MtInformation,[mbyes],0);
- exit;
- end;
- if Trim(LeSrvPort.Text )='' then
- begin
- MessageDlg('请输入服务器端口号!',MtInformation,[mbyes],0);
- exit;
- end
- else
- if (Strtoint(Trim(LeSrvPort.Text))<0) or (Strtoint(Trim(LeSrvPort.Text))>999999) then
- begin
- MessageDlg('服务器端口号就在0-9999之间!',MtInformation,[mbyes],0);
- exit;
- end;
- //ClientSocket.Active:=False;
- //IdUdpClient1.Active:=False;
- ClientSocket.Port:=Strtoint(Trim(LeSrvPort.Text));
- ClientSocket.Host:=trim(LeSrvName.Text);
- //IdUdpClient1.Host:=trim(LeSrvName.Text);
- //IdUdpClient1.Port:=ClientSocket.Port;
- //IdUdpClient1.Active:=true;
- ClientSocket.Active:=true;
- BtnSend.Enabled:=true;
- self.Connet.Enabled:=false;
- Except
- MessageBox(0,'连接失败,请查看服务端是否有启动!','',MB_OK + MB_ICONWARNING);
- end;
- end;
- procedure TFrmClient.FormCreate(Sender: TObject);
- begin
- BtnSend.Enabled:=false;
- end;
- procedure TFrmClient.LeSrvPortKeyPress(Sender: TObject; var Key: Char);
- begin
- if Not(Key in ['0'..'9',#10,#8,#13]) then
- begin
- Key:=#0;
- end;
- end;
- procedure TFrmClient.LeSrvNameKeyPress(Sender: TObject; var Key: Char);
- begin
- if Not(Key in ['0'..'9',#8,#10,#13,#46]) then
- begin
- Key:=#0;
- end;
- end;
- procedure TFrmClient.ClientSocketRead(Sender: TObject;
- Socket: TCustomWinSocket);
- var
- Len:Word;
- Buf:Array of Char;
- Msg:String;
- begin
- try
- Socket.ReceiveBuf(Len, 2);
- If Len <1 then Exit;
- SetLength(Buf,Len);
- Socket.ReceiveBuf(Buf[0],Len);
- SetLength(Msg,Len);
- Move(buf[0],Msg[1],Len);
- MemReadMsg.Lines.Add(Msg);
- MemReadMsg.Lines.Add(#13);
- except
- end;
- end;
- procedure TFrmClient.btnSendClick(Sender: TObject);
- Var
- Len:Word;
- Buf:Array of Char;
- Msg:String;
- Begin//前两个字节存放消息体内容长度)
- Msg:=Trim(MemSendMsg.Text);
- Len:=length(Msg);
- SetLength(Buf,Len+2);
- Move(len,Buf[0],2);
- Move(Msg[1],Buf[2],Len);
- ShowMessage(inttostr(high(Buf)));
- ClientSocket.Socket.SendBuf(Buf[0],Len+2);
- MemReadMsg.Lines.Add('自己:');
- MemReadMsg.Lines.Add(#13);
- MemReadMsg.Lines.Add(' '+Msg);
- MemReadMsg.Lines.Add(#13);
- end;
- end.
downloadUntClient.pas Source code
- Download Delphi implements a simple P2P chat program Source code
Related Source Codes/Software:
Delphi get system process port - Through a Windows dynamic link library system prov... 2012-02-18
Graduation: Delphi wages management system - A graduate student's graduation project of Delphi ... 2012-02-18
Simple Delphi calculator - Implements functions similar to the simple electro... 2012-02-18
RM files addresses a security check DELPHI implementation - When you're downloading movies in RM format, there... 2012-02-18
Delphi version of the Access database compression program v1.0 - We normally encounter useless data exists in the A... 2012-02-18
Delphi uses the MMS protocol to download streaming media file - Delphi uses the MMS protocol to download streaming... 2012-02-18
Delphi kanji literacy software full version - Delphi pupils ' Chinese character recognition soft... 2012-02-18
Delphi examples of using the Image control to display and draw text - The Delphi examples through the use of an Image co... 2012-02-18
Delphi screen touch cash register system source program - From the perspective of directory structure, this ... 2012-02-18
Children's mathematical arithmetic software in Delphi source code - The count of pupils is perfect according to the on... 2012-02-18
Delphi car rental company business management system - A car rental company's business management systems... 2012-02-18
Delphi major revision of the human resources management system source code - RedHR owned a large OFFICE of human resources mana... 2012-02-18
DELPHI pawn industry management system source code - Pawn shop of an integrated business management sys... 2012-02-18
Cool interface Delphi chat software source code - Interface is really cool? This is a small LAN chat... 2012-02-18
Delphi shield Ctrl+Alt+Del reqijian method - Real shielding theory of Delphi is this: using a r... 2012-02-18
Classic RPG games with Delphi source code - The actual and Diablo game or scene is similar in ... 2012-02-18
35 Delphi7 Indy instance package - Application example demonstrates a lot of Indy Dem... 2012-02-18
Delphi transportation company business management system - A Delphi transportation company business managemen... 2012-02-18
Using Delphi to achieve control of the camera - This procedure describes how to use DELPHI AVICAP3... 2012-02-18
Cell of the report component for Delphi example source program - UFIDA table company developed a report component, ... 2012-02-18