Java socket “successfully” connect to any IP on port 80
I'm trying to open a socket to a remote server, but I want to get an exception thrown if the other side is not responding. For some reason, any IP which I try with PORT 80 seems to "connect" even if it's a completely random IP.
I'll try to convey the issue with an example.
This will timeout and raise an exception:
Socket s = new Socket();
s.connect(new InetSocketAddress("1.2.3.4", 81), SOME_TIMEOUT_CONST);
On the other hand, the following will continue normally as if it connected successfully:
Socket s = new Socket();
s.connect(new InetSocketAddress("1.2.3.4", 80), SOME_TIMEOUT_CONST);
I can't seem to figure out the reason for that.
If this is the expected behavior, how can I check that in case 2 it did not actually connect?
Edit: I ran the same code on a friend's pc, and both cases timed out and raised an exception. So it's probably something with my Mac. No idea what...
java sockets
add a comment |
I'm trying to open a socket to a remote server, but I want to get an exception thrown if the other side is not responding. For some reason, any IP which I try with PORT 80 seems to "connect" even if it's a completely random IP.
I'll try to convey the issue with an example.
This will timeout and raise an exception:
Socket s = new Socket();
s.connect(new InetSocketAddress("1.2.3.4", 81), SOME_TIMEOUT_CONST);
On the other hand, the following will continue normally as if it connected successfully:
Socket s = new Socket();
s.connect(new InetSocketAddress("1.2.3.4", 80), SOME_TIMEOUT_CONST);
I can't seem to figure out the reason for that.
If this is the expected behavior, how can I check that in case 2 it did not actually connect?
Edit: I ran the same code on a friend's pc, and both cases timed out and raised an exception. So it's probably something with my Mac. No idea what...
java sockets
I believe port80
is used by web servers as a standard, but I'm not knowledgeable in the area; nor do I know if that has any bearing on what you're seeing.
– Slaw
Dec 29 '18 at 16:37
Interesting. According to this dupe with no accepted answer, it could be your firewall. Also found this on the Oracle forum from 2009 - also unanswered - that blames it on Vista.
– Johnny Mopp
Dec 29 '18 at 16:43
add a comment |
I'm trying to open a socket to a remote server, but I want to get an exception thrown if the other side is not responding. For some reason, any IP which I try with PORT 80 seems to "connect" even if it's a completely random IP.
I'll try to convey the issue with an example.
This will timeout and raise an exception:
Socket s = new Socket();
s.connect(new InetSocketAddress("1.2.3.4", 81), SOME_TIMEOUT_CONST);
On the other hand, the following will continue normally as if it connected successfully:
Socket s = new Socket();
s.connect(new InetSocketAddress("1.2.3.4", 80), SOME_TIMEOUT_CONST);
I can't seem to figure out the reason for that.
If this is the expected behavior, how can I check that in case 2 it did not actually connect?
Edit: I ran the same code on a friend's pc, and both cases timed out and raised an exception. So it's probably something with my Mac. No idea what...
java sockets
I'm trying to open a socket to a remote server, but I want to get an exception thrown if the other side is not responding. For some reason, any IP which I try with PORT 80 seems to "connect" even if it's a completely random IP.
I'll try to convey the issue with an example.
This will timeout and raise an exception:
Socket s = new Socket();
s.connect(new InetSocketAddress("1.2.3.4", 81), SOME_TIMEOUT_CONST);
On the other hand, the following will continue normally as if it connected successfully:
Socket s = new Socket();
s.connect(new InetSocketAddress("1.2.3.4", 80), SOME_TIMEOUT_CONST);
I can't seem to figure out the reason for that.
If this is the expected behavior, how can I check that in case 2 it did not actually connect?
Edit: I ran the same code on a friend's pc, and both cases timed out and raised an exception. So it's probably something with my Mac. No idea what...
java sockets
java sockets
edited Dec 30 '18 at 7:07
GuD
asked Dec 29 '18 at 16:16
GuDGuD
162
162
I believe port80
is used by web servers as a standard, but I'm not knowledgeable in the area; nor do I know if that has any bearing on what you're seeing.
– Slaw
Dec 29 '18 at 16:37
Interesting. According to this dupe with no accepted answer, it could be your firewall. Also found this on the Oracle forum from 2009 - also unanswered - that blames it on Vista.
– Johnny Mopp
Dec 29 '18 at 16:43
add a comment |
I believe port80
is used by web servers as a standard, but I'm not knowledgeable in the area; nor do I know if that has any bearing on what you're seeing.
– Slaw
Dec 29 '18 at 16:37
Interesting. According to this dupe with no accepted answer, it could be your firewall. Also found this on the Oracle forum from 2009 - also unanswered - that blames it on Vista.
– Johnny Mopp
Dec 29 '18 at 16:43
I believe port
80
is used by web servers as a standard, but I'm not knowledgeable in the area; nor do I know if that has any bearing on what you're seeing.– Slaw
Dec 29 '18 at 16:37
I believe port
80
is used by web servers as a standard, but I'm not knowledgeable in the area; nor do I know if that has any bearing on what you're seeing.– Slaw
Dec 29 '18 at 16:37
Interesting. According to this dupe with no accepted answer, it could be your firewall. Also found this on the Oracle forum from 2009 - also unanswered - that blames it on Vista.
– Johnny Mopp
Dec 29 '18 at 16:43
Interesting. According to this dupe with no accepted answer, it could be your firewall. Also found this on the Oracle forum from 2009 - also unanswered - that blames it on Vista.
– Johnny Mopp
Dec 29 '18 at 16:43
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53971201%2fjava-socket-successfully-connect-to-any-ip-on-port-80%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53971201%2fjava-socket-successfully-connect-to-any-ip-on-port-80%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
I believe port
80
is used by web servers as a standard, but I'm not knowledgeable in the area; nor do I know if that has any bearing on what you're seeing.– Slaw
Dec 29 '18 at 16:37
Interesting. According to this dupe with no accepted answer, it could be your firewall. Also found this on the Oracle forum from 2009 - also unanswered - that blames it on Vista.
– Johnny Mopp
Dec 29 '18 at 16:43