Questions tagged [inet-socket]
10 questions
9
votes
2 answers
Find free port in Java
I need to find a free port in a Java Application. Why doesn't the below code work? It always returns 0.
public int findFreePort() {
int portNumber = new InetSocketAddress(0).getPort();
return portNumber;
}
Java doc of new…

vineeth kumar
- 175
- 1
- 12
4
votes
1 answer
BSD Socket issue: inet_ntop returning "0.0.0.0"
I'm trying to get the IP of the machine a socket I've bound is listening on. The port number printed works fine, but the address is "0.0.0.0". Here's the relevant code. res has been passed to getaddrinfo and getsockname before getting to this…

Ben S
- 68,394
- 30
- 171
- 212
3
votes
3 answers
How can I map a local unix socket to an inet socket?
I'm curious if it is possible to map a UNIX socket on to an INET socket. The situation is simply that I'd like to connect to a MySQL server. Unfortunately it has INET sockets disabled and therefore I can only connect with UNIX sockets. The tools I'm…

Danny
- 13,194
- 4
- 31
- 36
1
vote
2 answers
What does Java InetSocketAddress look like .toString()?
I'm doing a .toString() on an InetSocketAddress. This is part of an Android websocket client that so far is failing to connect to the host.
Right now the output from a variable address.toString() looks like domain.com/72.xx.xxx.xx:8000 but from what…

crockpotveggies
- 12,682
- 12
- 70
- 140
0
votes
0 answers
InetSocketAddress for localhost
When I tried executing the code new InetSocketAddress("localhost", 3000); in java 13, the host is being resolved to localhost/127.0.0.1:3000 instead of resolving to localhost:3000.
Any idea why it is being resolved with the IP address of localhost…

Vibha
- 19
- 1
- 1
- 4
0
votes
1 answer
UnknownHostException is thrown while connecting to a valid ip port
When i try to connect to a socket (valid ip:port) UnknownHostException is thrown randomly!
Socket socket = new Socket();
socket.connect(new InetSocketAddress(ipAddress, port), 1000);
Our local application environment's /etc/resolve.conf is…

technaren
- 120
- 1
- 12
0
votes
1 answer
How to automatically connect to a server having multiple DNS entries, if 1 is down and only 1 IP address is working?
A particular website has 2 DNS entries, i.e. 2 IP addresses for same hostname. But, one of the IP address is not working, only 1 works.
I am trying to develop an HTTP Client without using HTTP libraries in Java. I am using Socket.connect(hostname,…

Kunal Lakhwani
- 3
- 2
0
votes
1 answer
Reachability test always returns false using inetsocketaddress
I am trying to check rechability of host by following code :
Socket socket = new Socket();
try
{
SocketAddress socketAddress = new InetSocketAddress(InetAddress.getByName("https://www.google.co.in"), 80);
…

Rujul1993
- 1,631
- 2
- 10
- 10
0
votes
1 answer
How to get port number of connected wifi in android?
I want to do print functionality in my android application using wifi printer. For that i have done following. But I dont know how i to get port number.i have refer the question asked before in which it tells that port number not required but how to…

shivani patel
- 225
- 1
- 8
- 22
0
votes
1 answer
Java/Android: getHostName() is always null with InetSocketAddress
I am using an Android app using a open source java library (Calimero). My code tries to get the Hostname and the Port using this code:
private static KNXNetworkLinkIP connect(InetSocketAddress isaLocalEP, InetSocketAddress isaRemoteEP)
{
…

Mokkapps
- 2,028
- 9
- 42
- 67