com.javonet.utils.TcpConnectionData Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javonet-java-sdk Show documentation
Show all versions of javonet-java-sdk Show documentation
Javonet allows you to reference and use modules or packages written in (Java/Kotlin/Groovy/Clojure, C#/VB.NET, Ruby, Perl, Python, JavaScript/TypeScript) like they were created in your technology.
It works on Linux/Windows and MacOS for applications created in JVM, CLR/Netcore, Perl, Python, Ruby, NodeJS, C++ or GoLang and gives you unparalleled freedom and flexibility with native performance in building your mixed-technologies products.
Let it be accessing best AI or cryptography libraries, devices SDKs, legacy client modules, internal custom packages or anything from public repositories available on NPM, Nuget, PyPI, Maven/Gradle, RubyGems or GitHub. Get free from programming languages barriers today!
For more information check out our guides at https://www.javonet.com/guides/v2/
package com.javonet.utils;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.Objects;
public class TcpConnectionData {
private String ipAddress = "";
private final int port;
public TcpConnectionData(String hostname, int port) throws UnknownHostException {
this.port = port;
InetAddress inetAddress = InetAddress.getByName(hostname);
this.ipAddress = inetAddress.getHostAddress();
}
public byte[] getAddressBytes() {
String[] ipAddress = this.ipAddress.split("\\.");
byte[] ipBytes = new byte[ipAddress.length];
for (int i = 0; i < ipAddress.length; i++) {
ipBytes[i] = (byte) Integer.parseInt(ipAddress[i]);
}
return ipBytes;
}
public byte[] getPortBytes() {
return new byte[]{
(byte) port,
((byte) (port >>> 8 & 0xFF))
};
}
@Override
public String toString() {
return ipAddress + ":" + port;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
TcpConnectionData that = (TcpConnectionData) o;
return port == that.port && ipAddress.equals(that.ipAddress);
}
@Override
public int hashCode() {
return Objects.hash(ipAddress, port);
}
}