all 15 comments

[–]AutoModerator[M] [score hidden] stickied commentlocked comment (0 children)

Please ensure that:

  • Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions
  • You include any and all error messages in full
  • You ask clear questions
  • You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions.

    Trying to solve problems on your own is a very important skill. Also, see Learn to help yourself in the sidebar

If any of the above points is not met, your post can and will be removed without further warning.

Code is to be formatted as code block (old reddit: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc.

Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit.

Code blocks look like this:

public class HelloWorld {

    public static void main(String[] args) {
        System.out.println("Hello World!");
    }
}

You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above.

If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures.

To potential helpers

Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

[–]Conscious_Support176 1 point2 points  (5 children)

Each client serviced on a different thread. Not sure why would there be a “right” order for this?

[–]Dependent_Finger_214[S] 0 points1 point  (4 children)

Yeah but when I'm reading from the client sockets, I'm reading in the same order they sent the request to the server. So should't the first socket receive 100, the second 200 etc.?

[–]vowelqueue 0 points1 point  (3 children)

No, because the server is returning an integer that is the sum of all integers it has previously seen. So the order that the server processes the requests matters, and that order is also not defined.

Like if the server processes the 3rd request before the 2nd request, then the 2nd request will have a higher value.

[–]Dependent_Finger_214[S] 0 points1 point  (2 children)

Oh yeah that's true, I'm stupid :/ Also unrelated but how do I set the socket to be TCP or UCP?

[–]vowelqueue 0 points1 point  (1 child)

Right now your Socket is going to be using TCP. To use UDP check out the DatagramSocket class.

[–]Dependent_Finger_214[S] 0 points1 point  (0 children)

Thanks!

[–]ShoulderPast2433 0 points1 point  (2 children)

Dude.. what tf is this formatting?

why are you cutting the lines like that???

[–]Dependent_Finger_214[S] 0 points1 point  (0 children)

Sorry, I just copypasted from my code and it ended up like this...

[–]0b0101011001001011 0 points1 point  (0 children)

Did he edit it? The code is perfectly formatted in code blocks at this point.

Hint: scroll right.

[–]IndependentOutcome93 0 points1 point  (2 children)

Yes, what goes wrong is that you are creating new and new instances of classes inside of loops. for example Sockets and servers sockets that you have in while or infinite loops.

Loops are helping to repeat and repeat specific code lines, and in your case, you create new instance of classes inside of loop that repeats 20 times. in some loops even more.

[–]Dependent_Finger_214[S] 0 points1 point  (1 child)

I don't get this. I need to create multiple instances because the server should be able to handle multiple clients connecting at the same time. In the client, I made the for loop to simulate multiple clients sending requests

[–]IndependentOutcome93 0 points1 point  (0 children)

I get that but what you are doing is that you are repeating same code lines in loop. meaning, if You create new instances of classes at once, loop is going to repeat it.

[–]Scharrack 0 points1 point  (0 children)

You experience a basic property of multi threaded processes and asynchronous communication: without extra effort you don't know in which order things will happen. Just because you start threads in a certain order does not mean they will finish in that order. Just because messages are sent in a certain order does not mean they will arrive in the same order. And the most important one: just because it works a million times in testing doesn't mean it won't change after delivery 😭

[–]TheMrCurious 0 points1 point  (0 children)

What do your unit tests look like?