当前位置: 首页>>代码示例>>Java>>正文


Java DatagramPacket.setSocketAddress方法代码示例

本文整理汇总了Java中java.net.DatagramPacket.setSocketAddress方法的典型用法代码示例。如果您正苦于以下问题:Java DatagramPacket.setSocketAddress方法的具体用法?Java DatagramPacket.setSocketAddress怎么用?Java DatagramPacket.setSocketAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.net.DatagramPacket的用法示例。


在下文中一共展示了DatagramPacket.setSocketAddress方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: send

import java.net.DatagramPacket; //导入方法依赖的package包/类
private void send(byte[] data) throws Exception{
	if(data == null){
		return;
	}
	if(ds == null){
		return;
	}
	DatagramPacket dp = new DatagramPacket(data,data.length);
	dp.setSocketAddress(ds.getRemoteSocketAddress());
	ds.send(dp);
	lastSent = System.currentTimeMillis();
	this.sentPackets++;
}
 
开发者ID:ahhblss,项目名称:ddpush,代码行数:14,代码来源:UDPClientBase.java

示例2: echo

import java.net.DatagramPacket; //导入方法依赖的package包/类
private void echo (String s) throws IOException{
    if ( (s == null) || (s.length() == 0) ){
        return;
    }
    byte[] b = s.getBytes();
    DatagramPacket echogram = new DatagramPacket(b,b.length);
    echogram.setSocketAddress(new InetSocketAddress(packet.getAddress(),packet.getPort()));
    datagramSocket.send(echogram);
}
 
开发者ID:SensorsINI,项目名称:jaer,代码行数:10,代码来源:RemoteControl.java

示例3: onDnsRequestReceived

import java.net.DatagramPacket; //导入方法依赖的package包/类
public void onDnsRequestReceived(IPHeader ipHeader,UDPHeader udpHeader,DnsPacket dnsPacket){
    if(!interceptDns(ipHeader,udpHeader,dnsPacket)){
        //转发DNS
        QueryState state = new QueryState();
        state.ClientQueryID =dnsPacket.Header.ID;
        state.QueryNanoTime = System.nanoTime();
        state.ClientIP = ipHeader.getSourceIP();
        state.ClientPort = udpHeader.getSourcePort();
        state.RemoteIP = ipHeader.getDestinationIP();
        state.RemotePort = udpHeader.getDestinationPort();

        // 转换QueryID
        m_QueryID++;// 增加ID
        dnsPacket.Header.setID(m_QueryID);

        synchronized (m_QueryArray) {
            clearExpiredQueries();//清空过期的查询,减少内存开销。
            m_QueryArray.put(m_QueryID, state);// 关联数据
        }

        InetSocketAddress remoteAddress = new InetSocketAddress(CommonMethods.ipIntToInet4Address(state.RemoteIP ), state.RemotePort);
        DatagramPacket packet = new DatagramPacket(udpHeader.m_Data, udpHeader.m_Offset+8, dnsPacket.Size);
        packet.setSocketAddress(remoteAddress);

        try {
            if(LocalVpnService.Instance.protect(m_Client)){
                m_Client.send(packet);
            }else {
                System.err.println("VPN protect udp socket failed.");
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
 
开发者ID:w22ee,项目名称:onekey-proxy-android,代码行数:37,代码来源:DnsProxy.java

示例4: onDnsRequestReceived

import java.net.DatagramPacket; //导入方法依赖的package包/类
public void onDnsRequestReceived(IPHeader ipHeader, UDPHeader udpHeader, DnsPacket dnsPacket) {
    if (!interceptDns(ipHeader, udpHeader, dnsPacket)) {
        //转发DNS
        QueryState state = new QueryState();
        state.ClientQueryID = dnsPacket.Header.ID;
        state.QueryNanoTime = System.nanoTime();
        state.ClientIP = ipHeader.getSourceIP();
        state.ClientPort = udpHeader.getSourcePort();
        state.RemoteIP = ipHeader.getDestinationIP();
        state.RemotePort = udpHeader.getDestinationPort();

        // 转换QueryID
        m_QueryID++;// 增加ID
        dnsPacket.Header.setID(m_QueryID);

        synchronized (m_QueryArray) {
            clearExpiredQueries();//清空过期的查询,减少内存开销。
            m_QueryArray.put(m_QueryID, state);// 关联数据
        }

        InetSocketAddress remoteAddress = new InetSocketAddress(CommonMethods.ipIntToInet4Address(state.RemoteIP), state.RemotePort);
        DatagramPacket packet = new DatagramPacket(udpHeader.m_Data, udpHeader.m_Offset + 8, dnsPacket.Size);
        packet.setSocketAddress(remoteAddress);

        try {
            if (LocalVpnService.Instance.protect(m_Client)) {
                m_Client.send(packet);
            } else {
                System.err.println("VPN protect udp socket failed.");
            }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }
}
 
开发者ID:IronMan001,项目名称:ss-android,代码行数:37,代码来源:DnsProxy.java


注:本文中的java.net.DatagramPacket.setSocketAddress方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。