How can I interrupt reading from inputstream
I am currently working on a server-client communication. On server-side, I have a Thread listening continuously for any incoming data from the client.
while ((foo = (Foo) objectInputSteam.readObject()) != null) ...
Sometimes I also need to send data from the server to the client. (Not as a direct response.) After sending some data to the client over the same socket, an exception will be thrown once new data reaches the server (0xAC).
As far as I know, this happens because the inputreader is reading while sending data over the same socket.
Is there any way to interrupt the listening thread while sending the data to the client or do I need to create a second socket on a different port for outgoing traffic?
java multithreading sockets tcplistener
|
show 1 more comment
I am currently working on a server-client communication. On server-side, I have a Thread listening continuously for any incoming data from the client.
while ((foo = (Foo) objectInputSteam.readObject()) != null) ...
Sometimes I also need to send data from the server to the client. (Not as a direct response.) After sending some data to the client over the same socket, an exception will be thrown once new data reaches the server (0xAC).
As far as I know, this happens because the inputreader is reading while sending data over the same socket.
Is there any way to interrupt the listening thread while sending the data to the client or do I need to create a second socket on a different port for outgoing traffic?
java multithreading sockets tcplistener
1
You might consider moving to a more event-driven approach, rather than trying to block. For example, this answer provides some discussion
– KevinO
Nov 15 '18 at 16:13
"As far as I know, this happens because the inputreader is reading while sending data over the same socket" - what are you basing that on?
– davmac
Nov 15 '18 at 16:22
I based the reason for the problem on this post: stackoverflow.com/a/2395269/8372579
– MarvinX
Nov 15 '18 at 16:26
@MarvinX that post does not say that there is any issue with reading while sending data over the same socket. It says that anObjectInputStreamexpects its input to come from a singleObjectOutputStream.
– davmac
Nov 15 '18 at 16:39
So the actual problem is the client sending from different ObjectOutoutStreans?
– MarvinX
Nov 15 '18 at 16:46
|
show 1 more comment
I am currently working on a server-client communication. On server-side, I have a Thread listening continuously for any incoming data from the client.
while ((foo = (Foo) objectInputSteam.readObject()) != null) ...
Sometimes I also need to send data from the server to the client. (Not as a direct response.) After sending some data to the client over the same socket, an exception will be thrown once new data reaches the server (0xAC).
As far as I know, this happens because the inputreader is reading while sending data over the same socket.
Is there any way to interrupt the listening thread while sending the data to the client or do I need to create a second socket on a different port for outgoing traffic?
java multithreading sockets tcplistener
I am currently working on a server-client communication. On server-side, I have a Thread listening continuously for any incoming data from the client.
while ((foo = (Foo) objectInputSteam.readObject()) != null) ...
Sometimes I also need to send data from the server to the client. (Not as a direct response.) After sending some data to the client over the same socket, an exception will be thrown once new data reaches the server (0xAC).
As far as I know, this happens because the inputreader is reading while sending data over the same socket.
Is there any way to interrupt the listening thread while sending the data to the client or do I need to create a second socket on a different port for outgoing traffic?
java multithreading sockets tcplistener
java multithreading sockets tcplistener
asked Nov 15 '18 at 16:09
MarvinXMarvinX
10610
10610
1
You might consider moving to a more event-driven approach, rather than trying to block. For example, this answer provides some discussion
– KevinO
Nov 15 '18 at 16:13
"As far as I know, this happens because the inputreader is reading while sending data over the same socket" - what are you basing that on?
– davmac
Nov 15 '18 at 16:22
I based the reason for the problem on this post: stackoverflow.com/a/2395269/8372579
– MarvinX
Nov 15 '18 at 16:26
@MarvinX that post does not say that there is any issue with reading while sending data over the same socket. It says that anObjectInputStreamexpects its input to come from a singleObjectOutputStream.
– davmac
Nov 15 '18 at 16:39
So the actual problem is the client sending from different ObjectOutoutStreans?
– MarvinX
Nov 15 '18 at 16:46
|
show 1 more comment
1
You might consider moving to a more event-driven approach, rather than trying to block. For example, this answer provides some discussion
– KevinO
Nov 15 '18 at 16:13
"As far as I know, this happens because the inputreader is reading while sending data over the same socket" - what are you basing that on?
– davmac
Nov 15 '18 at 16:22
I based the reason for the problem on this post: stackoverflow.com/a/2395269/8372579
– MarvinX
Nov 15 '18 at 16:26
@MarvinX that post does not say that there is any issue with reading while sending data over the same socket. It says that anObjectInputStreamexpects its input to come from a singleObjectOutputStream.
– davmac
Nov 15 '18 at 16:39
So the actual problem is the client sending from different ObjectOutoutStreans?
– MarvinX
Nov 15 '18 at 16:46
1
1
You might consider moving to a more event-driven approach, rather than trying to block. For example, this answer provides some discussion
– KevinO
Nov 15 '18 at 16:13
You might consider moving to a more event-driven approach, rather than trying to block. For example, this answer provides some discussion
– KevinO
Nov 15 '18 at 16:13
"As far as I know, this happens because the inputreader is reading while sending data over the same socket" - what are you basing that on?
– davmac
Nov 15 '18 at 16:22
"As far as I know, this happens because the inputreader is reading while sending data over the same socket" - what are you basing that on?
– davmac
Nov 15 '18 at 16:22
I based the reason for the problem on this post: stackoverflow.com/a/2395269/8372579
– MarvinX
Nov 15 '18 at 16:26
I based the reason for the problem on this post: stackoverflow.com/a/2395269/8372579
– MarvinX
Nov 15 '18 at 16:26
@MarvinX that post does not say that there is any issue with reading while sending data over the same socket. It says that an
ObjectInputStream expects its input to come from a single ObjectOutputStream.– davmac
Nov 15 '18 at 16:39
@MarvinX that post does not say that there is any issue with reading while sending data over the same socket. It says that an
ObjectInputStream expects its input to come from a single ObjectOutputStream.– davmac
Nov 15 '18 at 16:39
So the actual problem is the client sending from different ObjectOutoutStreans?
– MarvinX
Nov 15 '18 at 16:46
So the actual problem is the client sending from different ObjectOutoutStreans?
– MarvinX
Nov 15 '18 at 16:46
|
show 1 more 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%2f53323512%2fhow-can-i-interrupt-reading-from-inputstream%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%2f53323512%2fhow-can-i-interrupt-reading-from-inputstream%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
1
You might consider moving to a more event-driven approach, rather than trying to block. For example, this answer provides some discussion
– KevinO
Nov 15 '18 at 16:13
"As far as I know, this happens because the inputreader is reading while sending data over the same socket" - what are you basing that on?
– davmac
Nov 15 '18 at 16:22
I based the reason for the problem on this post: stackoverflow.com/a/2395269/8372579
– MarvinX
Nov 15 '18 at 16:26
@MarvinX that post does not say that there is any issue with reading while sending data over the same socket. It says that an
ObjectInputStreamexpects its input to come from a singleObjectOutputStream.– davmac
Nov 15 '18 at 16:39
So the actual problem is the client sending from different ObjectOutoutStreans?
– MarvinX
Nov 15 '18 at 16:46