记录当前远程和本地地址信息,方便外部使用
This commit is contained in:
parent
002b564047
commit
c9a4f35dc4
|
@ -46,15 +46,15 @@ bool UdpSocket::Process(IP_HEADER& ip, Stream& ms)
|
|||
if(!udp) return false;
|
||||
|
||||
ushort port = __REV16(udp->DestPort);
|
||||
//ushort remotePort = __REV16(udp->SrcPort);
|
||||
ushort remotePort = __REV16(udp->SrcPort);
|
||||
|
||||
// 仅处理本连接的IP和端口
|
||||
if(Port != 0 && port != Port) return false;
|
||||
|
||||
//Remote.Port = remotePort;
|
||||
//Remote.Address = ip.SrcIP;
|
||||
//Local.Port = port;
|
||||
//Local.Address = ip.DestIP;
|
||||
CurRemote.Port = remotePort;
|
||||
CurRemote.Address = ip.SrcIP;
|
||||
CurLocal.Port = port;
|
||||
CurLocal.Address = ip.DestIP;
|
||||
|
||||
#if NET_DEBUG
|
||||
byte* data = udp->Next();
|
||||
|
@ -79,27 +79,27 @@ void UdpSocket::OnProcess(IP_HEADER& ip, UDP_HEADER& udp, Stream& ms)
|
|||
// 触发ITransport接口事件
|
||||
uint len2 = OnReceive(data, len);
|
||||
// 如果有返回,说明有数据要回复出去
|
||||
if(len2) Write(data, len2);
|
||||
//if(len2) Write(data, len2);
|
||||
if(len2)
|
||||
{
|
||||
ByteArray bs(data, len2);
|
||||
Send(bs, CurRemote.Address, CurRemote.Port);
|
||||
}
|
||||
|
||||
IPAddress addr = ip.SrcIP;
|
||||
IPEndPoint remote(addr, __REV16(udp.SrcPort));
|
||||
if(OnReceived)
|
||||
{
|
||||
|
||||
// 返回值指示是否向对方发送数据包
|
||||
bool rs = OnReceived(*this, udp, remote, ms);
|
||||
if(rs && ms.Remain() > 0) Send(udp, len, remote.Address, remote.Port, false);
|
||||
bool rs = OnReceived(*this, udp, CurRemote, ms);
|
||||
if(rs && ms.Remain() > 0) Send(udp, len, CurRemote.Address, CurRemote.Port, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if NET_DEBUG
|
||||
addr = ip.DestIP;
|
||||
IPEndPoint local(addr, __REV16(udp.DestPort));
|
||||
|
||||
debug_printf("UDP ");
|
||||
remote.Show();
|
||||
CurRemote.Show();
|
||||
debug_printf(" => ");
|
||||
local.Show();
|
||||
CurLocal.Show();
|
||||
debug_printf(" Payload=%d udp_len=%d \r\n", len, __REV16(udp.Length));
|
||||
|
||||
Sys.ShowHex(data, len);
|
||||
|
|
|
@ -7,13 +7,13 @@
|
|||
class UdpSocket : public Socket, public ITransport
|
||||
{
|
||||
private:
|
||||
//UDP_HEADER* Create();
|
||||
|
||||
public:
|
||||
ushort Port; // 本地端口,接收该端口数据包。0表示接收所有端口的数据包
|
||||
ushort BindPort; // 绑定端口,用于发出数据包的源端口。默认为Port,若Port为0,则从1024算起,累加
|
||||
IPEndPoint Remote; // 远程地址
|
||||
//IPEndPoint Local; // 本地地址
|
||||
IPEndPoint Remote; // 远程地址。默认发送数据的目标地址
|
||||
IPEndPoint CurRemote; // 远程地址。本次收到数据的远程地址
|
||||
IPEndPoint CurLocal; // 本地地址
|
||||
|
||||
UdpSocket(TinyIP* tip);
|
||||
|
||||
|
|
Loading…
Reference in New Issue