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


Java DatagramPacket.getData方法代码示例

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


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

示例1: send

import java.net.DatagramPacket; //导入方法依赖的package包/类
/**
 * Sends the Datagram either through the proxy or directly depending on
 * current proxy settings and destination address. <BR>
 * 
 * <B> NOTE: </B> DatagramPacket size should be at least 10 bytes less than
 * the systems limit.
 * 
 * <P>
 * See documentation on java.net.DatagramSocket for full details on how to
 * use this method.
 * 
 * @param dp
 *            Datagram to send.
 * @throws IOException
 *             If error happens with I/O.
 */
public void send(DatagramPacket dp) throws IOException {
	// If the host should be accessed directly, send it as is.
	if (!server_mode && proxy.isDirect(dp.getAddress())) {
		super.send(dp);
		log.debug("Sending datagram packet directly:");
		return;
	}

	final byte[] head = formHeader(dp.getAddress(), dp.getPort());
	byte[] buf = new byte[head.length + dp.getLength()];
	final byte[] data = dp.getData();

	// Merge head and data
	System.arraycopy(head, 0, buf, 0, head.length);
	// System.arraycopy(data,dp.getOffset(),buf,head.length,dp.getLength());
	System.arraycopy(data, 0, buf, head.length, dp.getLength());

	if (encapsulation != null) {
		buf = encapsulation.udpEncapsulate(buf, true);
	}

	super.send(new DatagramPacket(buf, buf.length, relayIP, relayPort));
}
 
开发者ID:PanagiotisDrakatos,项目名称:T0rlib4Android,代码行数:40,代码来源:Socks5DatagramSocket.java

示例2: getMessageBlock

import java.net.DatagramPacket; //导入方法依赖的package包/类
/**
 * 解析MessageBlock
 * @param packet
 * @return
 * @throws Exception
 */
public MessageBlock getMessageBlock(DatagramPacket packet) throws UnsupportedEncodingException{
	
	
	String blockJson = new String(packet.getData(), 0, packet.getLength(), code);
	
	JSONObject messageBlockJsonO = new JSONObject();
	try {
		messageBlockJsonO = JSONObject.parseObject(blockJson);
	} catch (JSONException e) {
		//可能是重复或者错误的包
		return null;
	}
	
	MessageBlock msgBlock = JSONObject.toJavaObject(messageBlockJsonO, MessageBlock.class);
	msgBlock.setSender(packet.getAddress().toString());
	return msgBlock;
	
}
 
开发者ID:lmd,项目名称:multicast,代码行数:25,代码来源:TiandeMulticastMessageManager.java

示例3: getMessage

import java.net.DatagramPacket; //导入方法依赖的package包/类
/**
 * 接收消息
 */
public String getMessage()
{
	byte[] buf = new byte[1024];
	DatagramPacket dp = new DatagramPacket(buf, buf.length);
	try
	{
		socket.receive(dp);
		String message = new String(dp.getData(), 0, dp.getLength());
		System.out.println("使用UDP成功接收到:"+message);
		return message;
	}
	catch (Exception e)
	{
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:sxei,项目名称:myqq,代码行数:21,代码来源:UDP.java

示例4: startListening

import java.net.DatagramPacket; //导入方法依赖的package包/类
private static void startListening(){ 
	try{   
		while(Client.isConnected){  
			//Create the packet so we can receive data
			DatagramPacket packet = new DatagramPacket(new byte[Client.receive_buffer], Client.receive_buffer);
			//Wait till we receive data and fill the packet with the incoming data
			Client.socket.receive(packet);
			
			byte[] bd = packet.getData();
			String data = new String(bd, 0, bd.length).trim();
			
			analyzeData(data); 
		}
		//Close the receiving/sending data for this socket 
		Client.socket.close();
	}catch(IOException e){
		if(!Client.disconnecting) {
			String errorMessage = e.getMessage();
			if(!errorMessage.equals("socket closed"))
				System.out.println("Error occurred on the client: " + e.getMessage());  				
		}else Client.disconnecting = false;
	} 
}
 
开发者ID:giannismarinakis,项目名称:java-open-nl,代码行数:24,代码来源:Client.java

示例5: run

import java.net.DatagramPacket; //导入方法依赖的package包/类
@Override
public void run() {
	while (true) {
		DatagramPacket packet = new DatagramPacket(receive_str_byte, receive_str_byte.length);
		try {
			client.getDs().receive(packet);
			InetAddress address = packet.getAddress();
			int port = packet.getPort();
			int len = packet.getLength();
			byte[] data = packet.getData();

			System.out.printf("Request from %s Port %d:%n%s%n", address, port,
					new String(data, 0, len));
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
 
开发者ID:magcode,项目名称:sunricher-wifi-mqtt,代码行数:20,代码来源:UDPListener.java

示例6: verifyClientAuth

import java.net.DatagramPacket; //导入方法依赖的package包/类
/**
 * Returns true if the client has a valid auth, otherwise false
 */
private Boolean verifyClientAuth(DatagramPacket requestPacket)
{
    SocketAddress socketaddress = requestPacket.getSocketAddress();

    if (!this.queryClients.containsKey(socketaddress))
    {
        return Boolean.valueOf(false);
    }
    else
    {
        byte[] abyte = requestPacket.getData();
        return ((RConThreadQuery.Auth)this.queryClients.get(socketaddress)).getRandomChallenge() != RConUtils.getBytesAsBEint(abyte, 7, requestPacket.getLength()) ? Boolean.valueOf(false) : Boolean.valueOf(true);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:18,代码来源:RConThreadQuery.java

示例7: AckListMessage

import java.net.DatagramPacket; //导入方法依赖的package包/类
public AckListMessage(DatagramPacket dp){
	this.dp=dp;
	dpData=dp.getData();
	ver=ByteShortConvert.toShort(dpData, 0);
	sType=ByteShortConvert.toShort(dpData, 2);
	connectId=ByteIntConvert.toInt(dpData, 4);
	clientId=ByteIntConvert.toInt(dpData, 8);
	
	
	lastRead=ByteIntConvert.toInt(dpData, 4+8);
	int sum=ByteShortConvert.toShort(dpData, 8+8);
	ackList=new ArrayList<Integer>();
	int t=0;
	for(int i=0;i<sum;i++){
		t=10+4*i;
		int sequence=ByteIntConvert.toInt(dpData, t+8);
		ackList.add(sequence);
	}
	////#MLog.println("LLLLLLLLLLLLLL "+dp.getLength()+" "+ackList.size());
	t=10+4*sum-4;
	r1=ByteIntConvert.toInt(dpData, t+4+8);
	s1=ByteIntConvert.toInt(dpData, t+8+8);

	r2=ByteIntConvert.toInt(dpData, t+12+8);
	s2=ByteIntConvert.toInt(dpData, t+16+8);

	r3=ByteIntConvert.toInt(dpData, t+20+8);
	s3=ByteIntConvert.toInt(dpData, t+24+8);

	////#MLog.println("aaaaaaaaa"+r3+"kkkkkkk "+s3);
}
 
开发者ID:jonasxiao,项目名称:FinalSpeed,代码行数:32,代码来源:AckListMessage.java

示例8: getInputMAC

import java.net.DatagramPacket; //导入方法依赖的package包/类
public static String getInputMAC(DatagramPacket packet){
	byte[] data;
	byte[] mac = new byte[6];
	int j=0;
	data = packet.getData();
	for (int i=6; i<12; i++){
		mac[j] = data[i];
		j++;
	}
	return hexConvert(mac, true);
}
 
开发者ID:ivangundampc,项目名称:SleepOnLan,代码行数:12,代码来源:MagicPacket.java

示例9: run

import java.net.DatagramPacket; //导入方法依赖的package包/类
public void run()
{
    byte[] abyte = new byte[1024];

    while (!this.isInterrupted())
    {
        DatagramPacket datagrampacket = new DatagramPacket(abyte, abyte.length);

        try
        {
            this.socket.receive(datagrampacket);
        }
        catch (SocketTimeoutException var5)
        {
            continue;
        }
        catch (IOException ioexception)
        {
            LanServerDetector.logger.error((String)"Couldn\'t ping server", (Throwable)ioexception);
            break;
        }

        String s = new String(datagrampacket.getData(), datagrampacket.getOffset(), datagrampacket.getLength());
        LanServerDetector.logger.debug(datagrampacket.getAddress() + ": " + s);
        this.localServerList.func_77551_a(s, datagrampacket.getAddress());
    }

    try
    {
        this.socket.leaveGroup(this.broadcastAddress);
    }
    catch (IOException var4)
    {
        ;
    }

    this.socket.close();
}
 
开发者ID:Notoh,项目名称:DecompiledMinecraft,代码行数:39,代码来源:LanServerDetector.java

示例10: readBytesUdp

import java.net.DatagramPacket; //导入方法依赖的package包/类
public byte[] readBytesUdp(int len){
    byte[] b = new byte[len];
    DatagramPacket p = new DatagramPacket(b, len);
    if(dt != null){
       try {
           getDatagramSocket().receive(p);
       } catch (IOException ex) {
           Logger.getLogger(Established.class.getName()).log(Level.SEVERE, null, ex);
       }
    }
    return p.getData();
}
 
开发者ID:Obsidiam,项目名称:amelia,代码行数:13,代码来源:Transport.java

示例11: send

import java.net.DatagramPacket; //导入方法依赖的package包/类
@Override
public void send(DatagramPacket dp) throws IOException {
	byte[] data = dp.getData();
	final ByteBuffer writeBuffer = ByteBuffer.allocate(data.length);
	writeBuffer.clear();
	writeBuffer.put(dp.getData());
	writeBuffer.flip();
	TestServerConsole.log(getName() + " sending datagram: length = " 
				+ writeBuffer.array().length + ", to: " + dp.getSocketAddress(), 2, TestServerServiceEnum.UDP_SERVICE);
	channel.send(writeBuffer, dp.getSocketAddress());
}
 
开发者ID:rtr-nettest,项目名称:open-rmbt,代码行数:12,代码来源:NioUdpMultiClientServer.java

示例12: DataMessage

import java.net.DatagramPacket; //导入方法依赖的package包/类
public DataMessage(DatagramPacket dp){
	this.dp=dp;
	dpData=dp.getData();
	ver=ByteShortConvert.toShort(dpData, 0);
	sType=ByteShortConvert.toShort(dpData, 2);
	
	connectId=ByteIntConvert.toInt(dpData, 4);
	clientId=ByteIntConvert.toInt(dpData, 8);
	
	sequence=ByteIntConvert.toInt(dpData, 12);
	length=ByteShortConvert.toShort(dpData, 16);
	timeId=ByteIntConvert.toInt(dpData, 18);
	data=new byte[length];
	System.arraycopy(dpData, 22, data, 0, length);
}
 
开发者ID:jonasxiao,项目名称:FinalSpeed,代码行数:16,代码来源:DataMessage.java

示例13: CloseMessage_Stream

import java.net.DatagramPacket; //导入方法依赖的package包/类
public CloseMessage_Stream(DatagramPacket dp){
	this.dp=dp;
	dpData=dp.getData();
	ver=ByteShortConvert.toShort(dpData, 0);
	sType=ByteShortConvert.toShort(dpData, 2);
	
	connectId=ByteIntConvert.toInt(dpData, 4);
	clientId=ByteIntConvert.toInt(dpData, 8);
	closeOffset=ByteIntConvert.toInt(dpData, 12);
	////#MLog.println("vCloseMessagebbb"+clientId+"v");
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:12,代码来源:CloseMessage_Stream.java

示例14: PingMessage

import java.net.DatagramPacket; //导入方法依赖的package包/类
public PingMessage(DatagramPacket dp){
	this.dp=dp;
	dpData=dp.getData();
	ver=ByteShortConvert.toShort(dpData, 0);
	sType=ByteShortConvert.toShort(dpData, 2);
	connectId=ByteIntConvert.toInt(dpData, 4);
	clientId=ByteIntConvert.toInt(dpData, 8);
	pingId=ByteIntConvert.toInt(dpData, 12);
	downloadSpeed=ByteShortConvert.toShort(dpData, 16);
	uploadSpeed=ByteShortConvert.toShort(dpData, 18);
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:12,代码来源:PingMessage.java

示例15: CloseMessage_Conn

import java.net.DatagramPacket; //导入方法依赖的package包/类
public CloseMessage_Conn(DatagramPacket dp){
	this.dp=dp;
	dpData=dp.getData();
	ver=ByteShortConvert.toShort(dpData, 0);
	sType=ByteShortConvert.toShort(dpData, 2);
	connectId=ByteIntConvert.toInt(dpData, 4);
	clientId=ByteIntConvert.toInt(dpData, 8);
}
 
开发者ID:breakEval13,项目名称:NSS,代码行数:9,代码来源:CloseMessage_Conn.java


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