如何不通过SOCKET实现广域网通信,比如如何做一个可以实现聊天的工具(100分)

  • 主题发起人 主题发起人 yibb
  • 开始时间 开始时间
Y

yibb

Unregistered / Unconfirmed
GUEST, unregistred user!
自己写过一个可以实现局域网内聊天的程序,可是如何才能编出一个广域网间聊天的工具呢?
就象QQ一样,但是不要通过SOCKET。请高手指教!
 
刚刚看到这里:

procedure TfrmServer.NMUDPSendDataReceived(Sender: TComponent;
NumberBytes: Integer; FromIP: String; Port: Integer);
var
data:TMemoryStream;
buf:pchar;
SqlGetusers,MemoStr:string;
i,j:integer;
begin
j:=0;
i:=0;
//update view
Self.Caption:='Receive data';
//prepare stream
data:=TMemoryStream.Create;
//read stream
NMUDPSend.ReadStream(data);
//prepare memory
getmem(buf,NumberBytes+1);
FillChar(buf^,NumberBytes+1,0);
data.Read(buf^,NumberBytes);
//show received info
MemoStr:=string(buf);
if MemoStr='GetUser' then
begin
Query1.Close;
Query1.SQL.Clear;
Query1.SQL.Add( 'select * from users');
Query1.ExecSQL;
Query1.Open;
//i:=Query1.FieldCount;
while not Query1.Eof do
begin
for i:=0 to Query1.FieldCount-1 do
begin
SqlGetusers:=SqlGetusers+','+Query1.Fields.AsString;
end;
Query1.Next;
j:=j+1;
end;
ReturnMac(SqlGetusers,FromIP,Port);
end;
data.Free;
freemem(buf);
end;



function ReturnMac(Str,FromIP: String; Port: Integer):integer;
var
data:TMemoryStream;
buf:Pchar;
size:integer;
begin
//prepare buf
size:=length(Str);
GetMem(buf,size+1);
FillChar(buf^,size,#0);
//fill data
StrPCopy(buf,Str);
//prepare stream
data:=TMemoryStream.Create;
data.Write(buf^,size);
//set tsarget info
frmServer.NMUDPSend.RemoteHost:=FromIP;
frmServer.NMUDPSend.RemotePort:=Port;
//send package
frmServer.NMUDPSend.SendStream(data);
//free memory
FreeMem(buf);
data.Free;
end;
 
接受答案了.
 
后退
顶部