本文整理汇总了Java中java.net.DatagramPacket.getSocketAddress方法的典型用法代码示例。如果您正苦于以下问题:Java DatagramPacket.getSocketAddress方法的具体用法?Java DatagramPacket.getSocketAddress怎么用?Java DatagramPacket.getSocketAddress使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.net.DatagramPacket
的用法示例。
在下文中一共展示了DatagramPacket.getSocketAddress方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: receiveData
import java.net.DatagramPacket; //导入方法依赖的package包/类
private void receiveData() throws Exception{
DatagramPacket dp = new DatagramPacket(bufferArray, bufferArray.length);
ds.setSoTimeout(5*1000);
ds.receive(dp);
if(dp.getLength() <= 0 || dp.getData() == null || dp.getData().length == 0){
return;
}
byte[] data = new byte[dp.getLength()];
System.arraycopy(dp.getData(), 0, data, 0, dp.getLength());
Message m = new Message(dp.getSocketAddress(), data);
if(m.checkFormat() == false){
return;
}
this.receivedPackets++;
this.lastReceived = System.currentTimeMillis();
this.ackServer(m);
if(m.getCmd() == Message.CMD_0x00){
return;
}
this.enqueue(m);
worker.wakeup();
}
示例2: readingLoop
import java.net.DatagramPacket; //导入方法依赖的package包/类
private void readingLoop(CoapReceiver coapReceiver) {
byte[] readBuffer = new byte[2048];
try {
while (true) {
DatagramPacket datagramPacket = new DatagramPacket(readBuffer, readBuffer.length);
mcastSocket.receive(datagramPacket);
InetSocketAddress adr = (InetSocketAddress) datagramPacket.getSocketAddress();
if (LOGGER.isDebugEnabled() && adr.getAddress().isMulticastAddress()) {
LOGGER.debug("Received multicast message from: " + datagramPacket.getSocketAddress());
}
try {
final CoapPacket coapPacket = CoapPacket.read(adr, datagramPacket.getData(), datagramPacket.getLength());
receivedMessageWorker.execute(() -> coapReceiver.handle(coapPacket, TransportContext.NULL));
} catch (CoapException e) {
LOGGER.warn(e.getMessage());
}
}
} catch (IOException ex) {
if (!ex.getMessage().startsWith("Socket closed")) {
LOGGER.warn(ex.getMessage(), ex);
}
}
}
示例3: 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);
}
}
示例4: parseIncomingPacket
import java.net.DatagramPacket; //导入方法依赖的package包/类
/**
* Parses an incoming DatagramPacket, returning true if the packet was valid
*/
private boolean parseIncomingPacket(DatagramPacket requestPacket) throws IOException
{
byte[] abyte = requestPacket.getData();
int i = requestPacket.getLength();
SocketAddress socketaddress = requestPacket.getSocketAddress();
this.logDebug("Packet len " + i + " [" + socketaddress + "]");
if (3 <= i && -2 == abyte[0] && -3 == abyte[1])
{
this.logDebug("Packet \'" + RConUtils.getByteAsHexString(abyte[2]) + "\' [" + socketaddress + "]");
switch (abyte[2])
{
case 0:
if (!this.verifyClientAuth(requestPacket).booleanValue())
{
this.logDebug("Invalid challenge [" + socketaddress + "]");
return false;
}
else if (15 == i)
{
this.sendResponsePacket(this.createQueryResponse(requestPacket), requestPacket);
this.logDebug("Rules [" + socketaddress + "]");
}
else
{
RConOutputStream rconoutputstream = new RConOutputStream(1460);
rconoutputstream.writeInt(0);
rconoutputstream.writeByteArray(this.getRequestID(requestPacket.getSocketAddress()));
rconoutputstream.writeString(this.serverMotd);
rconoutputstream.writeString("SMP");
rconoutputstream.writeString(this.worldName);
rconoutputstream.writeString(Integer.toString(this.getNumberOfPlayers()));
rconoutputstream.writeString(Integer.toString(this.maxPlayers));
rconoutputstream.writeShort((short)this.serverPort);
rconoutputstream.writeString(this.queryHostname);
this.sendResponsePacket(rconoutputstream.toByteArray(), requestPacket);
this.logDebug("Status [" + socketaddress + "]");
}
default:
return true;
case 9:
this.sendAuthChallenge(requestPacket);
this.logDebug("Challenge [" + socketaddress + "]");
return true;
}
}
else
{
this.logDebug("Invalid packet [" + socketaddress + "]");
return false;
}
}
示例5: parseIncomingPacket
import java.net.DatagramPacket; //导入方法依赖的package包/类
/**
* Parses an incoming DatagramPacket, returning true if the packet was valid
*/
private boolean parseIncomingPacket(DatagramPacket requestPacket) throws IOException
{
byte[] abyte = requestPacket.getData();
int i = requestPacket.getLength();
SocketAddress socketaddress = requestPacket.getSocketAddress();
this.logDebug("Packet len " + i + " [" + socketaddress + "]");
if (3 <= i && -2 == abyte[0] && -3 == abyte[1])
{
this.logDebug("Packet \'" + RConUtils.getByteAsHexString(abyte[2]) + "\' [" + socketaddress + "]");
switch (abyte[2])
{
case 0:
if (!this.verifyClientAuth(requestPacket).booleanValue())
{
this.logDebug("Invalid challenge [" + socketaddress + "]");
return false;
}
else if (15 == i)
{
this.sendResponsePacket(this.createQueryResponse(requestPacket), requestPacket);
this.logDebug("Rules [" + socketaddress + "]");
}
else
{
RConOutputStream rconoutputstream = new RConOutputStream(1460);
rconoutputstream.writeInt(0);
rconoutputstream.writeByteArray(this.getRequestID(requestPacket.getSocketAddress()));
rconoutputstream.writeString(this.serverMotd);
rconoutputstream.writeString("SMP");
rconoutputstream.writeString(this.worldName);
rconoutputstream.writeString(Integer.toString(this.getNumberOfPlayers()));
rconoutputstream.writeString(Integer.toString(this.maxPlayers));
rconoutputstream.writeShort((short)this.serverPort);
rconoutputstream.writeString(this.queryHostname);
this.sendResponsePacket(rconoutputstream.toByteArray(), requestPacket);
this.logDebug("Status [" + socketaddress + "]");
}
default:
return true;
case 9:
this.sendAuthChallenge(requestPacket);
this.logDebug("Challenge [" + socketaddress + "]");
return true;
}
}
else
{
this.logDebug("Invalid packet [" + socketaddress + "]");
return false;
}
}