use of java.net.DatagramSocket in project camel by apache.
the class Mina2UdpTest method sendUdpMessages.
protected void sendUdpMessages() throws Exception {
DatagramSocket socket = new DatagramSocket();
try {
InetAddress address = InetAddress.getByName("127.0.0.1");
for (int i = 0; i < messageCount; i++) {
String text = "Hello Message: " + Integer.toString(i);
byte[] data = text.getBytes();
DatagramPacket packet = new DatagramPacket(data, data.length, address, getPort());
socket.send(packet);
}
Thread.sleep(2000);
} finally {
socket.close();
}
}
use of java.net.DatagramSocket in project camel by apache.
the class MinaUdpTest method sendUdpMessages.
protected void sendUdpMessages() throws Exception {
DatagramSocket socket = new DatagramSocket();
try {
InetAddress address = InetAddress.getByName("127.0.0.1");
for (int i = 0; i < messageCount; i++) {
String text = "Hello Message: " + i;
byte[] data = text.getBytes();
DatagramPacket packet = new DatagramPacket(data, data.length, address, getPort());
socket.send(packet);
Thread.sleep(100);
}
} finally {
socket.close();
}
}
use of java.net.DatagramSocket in project hadoop by apache.
the class PrivilegedNfsGatewayStarter method init.
@Override
public void init(DaemonContext context) throws Exception {
System.err.println("Initializing privileged NFS client socket...");
NfsConfiguration conf = new NfsConfiguration();
int clientPort = conf.getInt(NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY, NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_DEFAULT);
if (clientPort < 1 || clientPort > 1023) {
throw new RuntimeException("Must start privileged NFS server with '" + NfsConfigKeys.DFS_NFS_REGISTRATION_PORT_KEY + "' configured to a " + "privileged port.");
}
try {
InetSocketAddress socketAddress = new InetSocketAddress("localhost", clientPort);
registrationSocket = new DatagramSocket(null);
registrationSocket.setReuseAddress(true);
registrationSocket.bind(socketAddress);
} catch (SocketException e) {
LOG.error("Init failed for port=" + clientPort, e);
throw e;
}
args = context.getArguments();
}
use of java.net.DatagramSocket in project hadoop by apache.
the class TestUdpServer method testRequest.
static void testRequest(XDR request, XDR request2) {
try {
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("localhost");
byte[] sendData = request.getBytes();
byte[] receiveData = new byte[65535];
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, Nfs3Constant.SUN_RPCBIND);
clientSocket.send(sendPacket);
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket);
clientSocket.close();
} catch (UnknownHostException e) {
System.err.println("Don't know about host: localhost.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for " + "the connection to: localhost.");
System.exit(1);
}
}
use of java.net.DatagramSocket in project hadoop by apache.
the class TestPortmap method testRegistration.
@Test(timeout = 1000)
public void testRegistration() throws IOException, InterruptedException {
XDR req = new XDR();
RpcCall.getInstance(++xid, RpcProgramPortmap.PROGRAM, RpcProgramPortmap.VERSION, RpcProgramPortmap.PMAPPROC_SET, new CredentialsNone(), new VerifierNone()).write(req);
PortmapMapping sent = new PortmapMapping(90000, 1, PortmapMapping.TRANSPORT_TCP, 1234);
sent.serialize(req);
byte[] reqBuf = req.getBytes();
DatagramSocket s = new DatagramSocket();
DatagramPacket p = new DatagramPacket(reqBuf, reqBuf.length, pm.getUdpServerLoAddress());
try {
s.send(p);
} finally {
s.close();
}
// Give the server a chance to process the request
Thread.sleep(100);
boolean found = false;
@SuppressWarnings("unchecked") Map<String, PortmapMapping> map = (Map<String, PortmapMapping>) Whitebox.getInternalState(pm.getHandler(), "map");
for (PortmapMapping m : map.values()) {
if (m.getPort() == sent.getPort() && PortmapMapping.key(m).equals(PortmapMapping.key(sent))) {
found = true;
break;
}
}
Assert.assertTrue("Registration failed", found);
}
Aggregations