begin
NMUDP1.RemoteHost :=ListBox1.Items[i];//远程主机的名称或地址.
NMUDP1.SendStream(MyStream);//发送信息.
End;
end
else 如果私聊
begin
NMUDP1.RemoteHost :=ListBox1.Items[ListBox1.itemindex]; file://仅对所选中的网友.
NMUDP1.SendStream(MyStream);
End;
finally
MyStream.Free;
end;
Edit1.Text:='''''''';
Edit1.SetFocus;
end else
Edit1.SetFocus;
end;
procedure TForm1.NMUDP1DataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
MyStream: TMemoryStream;
TmpStr: String;
begin
MyStream := TMemoryStream.Create;
try
NMUDP1.ReadStream(MyStream);
SetLength(TmpStr,NumberBytes);
MyStream.Read(TmpStr,NumberBytes);
Memo1.Lines.Add(TmpStr); file://显示对话的内容.
finally
MyStream.Free;
end;
end;
procedure TForm1.Edit1KeyPress(Sender: TObject; var Key: Char);
var
MyStream: TMemoryStream;
TmpStr: String;
i:integer;
Begin
if (key=#13) and (Edit1.Text<>'''''''') then file://如果所说的内容不为空,且最后一个按键为"Enter",则发送。
begin
NMUDP1.ReportLevel := Status_Basic;
NMUDP1.RemotePort :=8888;
if ListBox1.Items[ListBox1.ItemIndex]=ComputerName then
Edit1.Text:=ComputerName+''''自言自语道:''''+Edit1.Text
else
Edit1.Text:=ComputerName+''''对''''+ListBox1.Items[listbox1.itemindex]+''''说:''''+Edit1.Text;
TmpStr :=Edit1.text;
MyStream := TMemoryStream.Create;
try
MyStream.Write(TmpStr, Length(Edit1.Text));
if ListBox1.ItemIndex=0 then
begin
for i:=1 to ListBox1.Items.Count-1 do
begin
NMUDP1.RemoteHost :=ListBox1.Items[i];
NMUDP1.SendStream(MyStream);
end;
end
else
begin
NMUDP1.RemoteHost :=ListBox1.Items[ListBox1.itemindex];
NMUDP1.SendStream(MyStream);
end;
finally
MyStream.Free;
end;
Edit1.Text:='''''''';
edit1.SetFocus;
end else
Edit1.SetFocus;
end;
procedure TForm1.Button1Click(Sender: TObject);
var
InputString:String;
begin file://增加网友,输入的可以是IP地址或
计算机名称。
InputString:=InputBox(''''增加人员'''', ''''IP地址或
计算机名'''', '''''''');
if Inputstring<>'''''''' then ListBox1.I