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


Java DatagramPacket.setPort方法代码示例

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


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

示例1: create

import java.net.DatagramPacket; //导入方法依赖的package包/类
public void create(int timeId){
	this.timeId=timeId;
	dpData=new byte[this.length+16+8];
	ByteShortConvert.toByteArray(ver, dpData, 0);  //add: ver
	ByteShortConvert.toByteArray(sType, dpData, 2);  //add: service type
	
	ByteIntConvert.toByteArray(connectId, dpData, 4); //add: sequence
	ByteIntConvert.toByteArray(clientId, dpData, 8); //add: sequence
	
	ByteIntConvert.toByteArray(this.sequence, dpData, 12); //add: sequence
	ByteShortConvert.toByteArray((short) this.length, dpData, 16); //add:length
	ByteIntConvert.toByteArray(this.timeId, dpData, 18); //add: sequence
	System.arraycopy(this.data, 0, dpData, 22, this.length);
	dp=new DatagramPacket(dpData,dpData.length);
	dp.setAddress(dstAddress);
	dp.setPort(dstPort);
	
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:19,代码来源:DataMessage.java

示例2: sendTrapMessage

import java.net.DatagramPacket; //导入方法依赖的package包/类
/**
 * Send the specified message on trapSocket.
 */
private void sendTrapMessage(SnmpMessage msg)
    throws IOException, SnmpTooBigException {

    byte[] buffer = new byte[bufferSize] ;
    DatagramPacket packet = new DatagramPacket(buffer, buffer.length) ;
    int encodingLength = msg.encodeMessage(buffer) ;
    packet.setLength(encodingLength) ;
    packet.setAddress(msg.address) ;
    packet.setPort(msg.port) ;
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "sendTrapMessage", "sending trap to " + msg.address + ":" +
              msg.port);
    }
    trapSocket.send(packet) ;
    if (SNMP_ADAPTOR_LOGGER.isLoggable(Level.FINER)) {
        SNMP_ADAPTOR_LOGGER.logp(Level.FINER, dbgTag,
            "sendTrapMessage", "sent to " + msg.address + ":" +
              msg.port);
    }
    snmpOutTraps++;
    snmpOutPkts++;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:27,代码来源:SnmpAdaptorServer.java

示例3: sendPacket

import java.net.DatagramPacket; //导入方法依赖的package包/类
public void sendPacket(InetAddress address, int port, byte[] payload, int offset, int length) {
    if (address == null)
        return;
    if (Looper.myLooper() == Looper.getMainLooper()) {
        new Thread(() -> sendPacket(address, port, payload, offset, length));
        return;
    }
    DatagramPacket packet = new DatagramPacket(payload, length);
    packet.setAddress(address);
    packet.setPort(port);
    try {
        socket.send(packet);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
开发者ID:Jack-Q,项目名称:messenger,代码行数:17,代码来源:PeerTransmission.java

示例4: detectMac_udp

import java.net.DatagramPacket; //导入方法依赖的package包/类
private void detectMac_udp(){
	for(int i=0;i<10;i++){
		try {
			DatagramSocket ds=new DatagramSocket();
			DatagramPacket dp=new DatagramPacket(new byte[1000], 1000);
			dp.setAddress(InetAddress.getByName(testIp_udp));
			dp.setPort(5555);
			ds.send(dp);
			ds.close();
			Thread.sleep(500);
			if(local_mac!=null){
				break;
			}
		} catch (Exception e) {
			e.printStackTrace();
			try {
				Thread.sleep(1);
			} catch (InterruptedException e1) {
				e1.printStackTrace();
			}
		}
	}

}
 
开发者ID:jonasxiao,项目名称:FinalSpeed,代码行数:25,代码来源:CapEnv.java

示例5: init

import java.net.DatagramPacket; //导入方法依赖的package包/类
public void init() throws IOException {
    setupSocket();
    sendPacket = new DatagramPacket(new byte[MAX_PACKET_SIZE],MAX_PACKET_SIZE);
    sendPacket.setAddress(address);
    sendPacket.setPort(port);
    receivePacket = new DatagramPacket(new byte[MAX_PACKET_SIZE],MAX_PACKET_SIZE);
    receivePacket.setAddress(address);
    receivePacket.setPort(port);
    member.setCommand(new byte[0]);
    member.getData(true, true);
    if ( membership == null ) membership = new Membership(member);
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:13,代码来源:McastServiceImpl.java

示例6: receive

import java.net.DatagramPacket; //导入方法依赖的package包/类
public synchronized void receive(DatagramPacket p) throws IOException {
	TunData td=null;
	try {
		td=packetList.take();
		p.setData(td.data);
		p.setLength(td.data.length);
		p.setAddress(td.tun.remoteAddress);
		p.setPort(CapEnv.toUnsigned(td.tun.remotePort));
	} catch (InterruptedException e) {
		e.printStackTrace();
	}
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:13,代码来源:VDatagramSocket.java

示例7: init

import java.net.DatagramPacket; //导入方法依赖的package包/类
public void init() throws IOException {
	setupSocket();
	sendPacket = new DatagramPacket(new byte[MAX_PACKET_SIZE], MAX_PACKET_SIZE);
	sendPacket.setAddress(address);
	sendPacket.setPort(port);
	receivePacket = new DatagramPacket(new byte[MAX_PACKET_SIZE], MAX_PACKET_SIZE);
	receivePacket.setAddress(address);
	receivePacket.setPort(port);
	member.setCommand(new byte[0]);
	member.getData(true, true);
	if (membership == null)
		membership = new Membership(member);
}
 
开发者ID:how2j,项目名称:lazycat,代码行数:14,代码来源:McastServiceImpl.java

示例8: receive

import java.net.DatagramPacket; //导入方法依赖的package包/类
/**
 * Receives udp packet. If packet have arrived from the proxy relay server,
 * it is processed and address and port of the packet are set to the address
 * and port of sending host.<BR>
 * If the packet arrived from anywhere else it is not changed.<br>
 * <B> NOTE: </B> DatagramPacket size should be at least 10 bytes bigger
 * than the largest packet you expect (this is for IPV4 addresses). For
 * hostnames and IPV6 it is even more.
 * 
 * @param dp
 *            Datagram in which all relevent information will be copied.
 */
public void receive(DatagramPacket dp) throws IOException {
	super.receive(dp);

	if (server_mode) {
		// Drop all datagrams not from relayIP/relayPort
		final int init_length = dp.getLength();
		final int initTimeout = getSoTimeout();
		final long startTime = System.currentTimeMillis();

		while (!relayIP.equals(dp.getAddress())
				|| (relayPort != dp.getPort())) {

			// Restore datagram size
			dp.setLength(init_length);

			// If there is a non-infinit timeout on this socket
			// Make sure that it happens no matter how often unexpected
			// packets arrive.
			if (initTimeout != 0) {
				final long passed = System.currentTimeMillis() - startTime;
				final int newTimeout = initTimeout - (int) passed;

				if (newTimeout <= 0) {
					throw new InterruptedIOException(
							"In Socks5DatagramSocket->receive()");
				}
				setSoTimeout(newTimeout);
			}

			super.receive(dp);
		}

		// Restore timeout settings
		if (initTimeout != 0) {
			setSoTimeout(initTimeout);
		}

	} else if (!relayIP.equals(dp.getAddress())
			|| (relayPort != dp.getPort())) {
		return; // Recieved direct packet
		// If the datagram is not from the relay server, return it it as is.
	}

	byte[] data;
	data = dp.getData();

	if (encapsulation != null) {
		data = encapsulation.udpEncapsulate(data, false);
	}

	// FIXME: What is this?
	final int offset = 0; // Java 1.1
	// int offset = dp.getOffset(); //Java 1.2

	final ByteArrayInputStream bIn = new ByteArrayInputStream(data, offset,
			dp.getLength());

	final ProxyMessage msg = new Socks5Message(bIn);
	dp.setPort(msg.port);
	dp.setAddress(msg.getInetAddress());

	// what wasn't read by the Message is the data
	final int data_length = bIn.available();
	// Shift data to the left
	System.arraycopy(data, offset + dp.getLength() - data_length, data,
			offset, data_length);

	dp.setLength(data_length);
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4j,代码行数:82,代码来源:Socks5DatagramSocket.java


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