use of java.net.SocketAddress in project pinpoint by naver.
the class NetworkAvailabilityCheckPacketFilterTest method testFilter.
@Test
public void testFilter() throws Exception {
SocketAddress localSocketAddress = senderSocket.getLocalSocketAddress();
logger.debug("localSocket:{}", localSocketAddress);
NetworkAvailabilityCheckPacket packet = new NetworkAvailabilityCheckPacket();
boolean skipResult = filter.filter(receiverSocket, packet, new InetSocketAddress("localhost", senderSocket.getLocalPort()));
Assert.assertEquals(skipResult, TBaseFilter.BREAK);
DatagramPacket receivePacket = new DatagramPacket(new byte[100], 100);
senderSocket.receive(receivePacket);
Assert.assertEquals(receivePacket.getLength(), NetworkAvailabilityCheckPacket.DATA_OK.length);
Assert.assertArrayEquals(Arrays.copyOf(receivePacket.getData(), NetworkAvailabilityCheckPacket.DATA_OK.length), NetworkAvailabilityCheckPacket.DATA_OK);
}
use of java.net.SocketAddress in project openhab1-addons by openhab.
the class S7Client method TCPConnect.
private int TCPConnect() {
SocketAddress sockaddr = new InetSocketAddress(IPAddress, ISOTCP);
LastError = 0;
try {
TCPSocket = new Socket();
TCPSocket.connect(sockaddr, 5000);
TCPSocket.setTcpNoDelay(true);
InStream = new DataInputStream(TCPSocket.getInputStream());
OutStream = new DataOutputStream(TCPSocket.getOutputStream());
} catch (IOException e) {
LastError = errTCPConnectionFailed;
}
return LastError;
}
use of java.net.SocketAddress in project openhab1-addons by openhab.
the class TCPConnector method open.
/**
* {@inheritDoc}
**/
public void open() {
try {
tcpSocket = new Socket();
SocketAddress TPIsocketAddress = new InetSocketAddress(ipAddress, tcpPort);
tcpSocket.connect(TPIsocketAddress, connectTimeout);
tcpOutput = new OutputStreamWriter(tcpSocket.getOutputStream(), "US-ASCII");
tcpInput = new BufferedReader(new InputStreamReader(tcpSocket.getInputStream()));
connected = true;
// Start the TCP Listener
TCPListener = new TCPListener();
TCPListener.start();
} catch (UnknownHostException exception) {
logger.error("open(): Unknown Host Exception: ", exception);
connected = false;
} catch (SocketException socketException) {
logger.error("open(): Socket Exception: ", socketException);
connected = false;
} catch (IOException ioException) {
logger.error("open(): IO Exception: ", ioException);
connected = false;
} catch (Exception exception) {
logger.error("open(): Exception: ", exception);
connected = false;
}
}
use of java.net.SocketAddress in project XobotOS by xamarin.
the class DatagramChannelImpl method receiveImpl.
private SocketAddress receiveImpl(ByteBuffer target, boolean loop) throws IOException {
SocketAddress retAddr = null;
DatagramPacket receivePacket;
int oldposition = target.position();
int received = 0;
// TODO: disallow mapped buffers and lose this conditional?
if (target.hasArray()) {
receivePacket = new DatagramPacket(target.array(), target.position() + target.arrayOffset(), target.remaining());
} else {
receivePacket = new DatagramPacket(new byte[target.remaining()], target.remaining());
}
do {
received = IoBridge.recvfrom(false, fd, receivePacket.getData(), receivePacket.getOffset(), receivePacket.getLength(), 0, receivePacket, isConnected());
if (receivePacket != null && receivePacket.getAddress() != null) {
if (received > 0) {
if (target.hasArray()) {
target.position(oldposition + received);
} else {
// copy the data of received packet
target.put(receivePacket.getData(), 0, received);
}
}
retAddr = receivePacket.getSocketAddress();
break;
}
} while (loop);
return retAddr;
}
use of java.net.SocketAddress in project tdi-studio-se by Talend.
the class DynamicsCRMClient method getProxy.
/**
* Get the proxy setting if there is proxy for system
*/
private Proxy getProxy() {
String proxyHost = System.getProperty("https.proxyHost");
String proxyPort = System.getProperty("https.proxyPort");
if (proxyHost != null) {
int port = -1;
if (proxyPort != null && proxyPort.length() > 0) {
port = Integer.parseInt(proxyPort);
}
SocketAddress addr = new InetSocketAddress(proxyHost, port);
Proxy proxy = new Proxy(Proxy.Type.HTTP, addr);
return proxy;
}
return null;
}
Aggregations