6 kyu
Basic socket server
166 of 195potzko
Loading description...
Backend
View
This comment has been reported as {{ abuseKindText }}.
Show
This comment has been hidden. You can view it now .
This comment can not be viewed.
- |
- Reply
- Edit
- View Solution
- Expand 1 Reply Expand {{ comments?.length }} replies
- Collapse
- Spoiler
- Remove
- Remove comment & replies
- Report
{{ fetchSolutionsError }}
-
-
Your rendered github-flavored markdown will appear here.
-
Label this discussion...
-
No Label
Keep the comment unlabeled if none of the below applies.
-
Issue
Use the issue label when reporting problems with the kata.
Be sure to explain the problem clearly and include the steps to reproduce. -
Suggestion
Use the suggestion label if you have feedback on how this kata can be improved.
-
Question
Use the question label if you have questions and/or need help solving the kata.
Don't forget to mention the language you're using, and mark as having spoiler if you include your solution.
-
No Label
- Cancel
Commenting is not allowed on this discussion
You cannot view this solution
There is no solution to show
Please sign in or sign up to leave a comment.
Hi, great topic, but I met some problems. I was writting in java.
1.I dont understand how could I throw IOException. I simply close the connection, but tests say "Expected java.io.IOException to be thrown, but nothing was thrown" When I add exception signature test does not work. I dont really know what to do. Is it my or tests problem? 2.The description says the port is 1111, but tests works in 80. This is distracting .
Python : I don't know if it's just me, but it seems like most of the solutions aren't working.
It also gives me the illusion, but if it is possible, it would be strange for those katas that cannot be solved
Please, C translation
Python full tests:
basic_tests()
should be decorated with@test.describe('basic tests')
basic_tests()
should not be called explicitelyrandom_check()
andexit_check()
should beit
blocks, notdescribe
blocksthanks, :)
One more thing: Although port
80
is the default HTTP port, in most cases, it's already being used by another server. Which puts this kata at risk of port collision. I'd recommend following the same guideline as implemented for Simple Socket Client and switching to port1111
.Correct, there is a small chance of collision. This was the first socket kata on the website and I didn't plan it well, hence the 1111 port was a temporary fix to use a less common port. However, it is not the ideal solution. If I were to rewrite it, I would pass a free port, as I did in my other katas (https://www.codewars.com/kata/639264354fc2d9001b4d243f for example). However, there are already 60 solutions to this kata, so I don't want to change the requirements and invalidate them
tbh using 80 was extra dumb as it's not even a http server lol
Well, there is no need to make a breaking change. We can adjust the sample code & description to start utilizing 1111 (or any other) instead of 80. To keep existing solutions compatible, all we need is to add an extra step to solution tests:
It should be pretty straightforward. Let me know if you need any help with it.
Edit: the reason why I raised this, is because I actually hit the collision :)
I went ahead and did just that, ty for your suggestion
nitpick: a minor typo in the description -
other th[A]n "exit"
I updated the description, thanks :)
Thank you very much for this kata. Having some trouble figuring out networking and i had a lot of fun clearing some stuff up step by step with this one.
glad you enjoyed it :)
This requirement is impossible for a stream-oriented protocol. If I send every byte as soon as it arrives, the tests fail. If I pause sending when "e" is received until I can make sure it's not followed by "xit", the tests fail too.
you could view tcp as 2 byet streams however this kata is more built around the blocking socket type from the standard library. I did add the guerentee that each string ends with a new line char to accommodate coding around the non blocking version of a tcp socket I changed the description to match the change
note that the blocking implemantation is built around the streamd protocol so this is technicly still possible even without these changes however it does become much harder as you have to check the timing between my packets to "guess" when im done sending or just hardcode that I send packets in groups of about 200 milliseconds to still finish all the tests in time
The tests output still contains headers with red arrows.
fixed
The required protocol isn't specified, but seems to be TCP. It's impossible to receive a packet using a stream-oriented protocol.
The description has been modified.
Random tests is improperly using the testing framework. Please note the proper usage of the testing framework: You're supposed to put test assertions inside
test.it
, nottest.describe
(however you can nesttest.describe
more than once before anytest.it
), and eachtest.it
block should have at least 1 test assertion.you are correct, I changed the test to function as expected
What is the maximum message length? Almost every solution (including author setup on all the current socket katas) doesn't actually ensure the full message is received before processing the message. This will cause problems for specifically crafted inputs.
I have revised the prompt, thanks
Listen to which host? For the purpose of the kata
127.0.0.1
/localhost
is fine, but this will not be fine for actual use of the socket by anyone else; and listening to any host is kinda a bad idea. So at least this should be specified.I have revised the prompt, thanks
I think
basic_tests
function should be wrapped into@test.describe('smth')
— with the deletion of the function call at the end, of course :)Also, is it normal that I get the following error:
I think that's the part of checking if the connection has been closed, but maybe that should be written in the description, smth like
Ignore the stderr output
?Double-also, why is
client.send("did you close the connection?")
without.encode()
? If I try to put it, my solution will crash, because the server will be "working" and thus callingtest.fail(...)
=/you are correct about the exit test, I replaced it with something a bit better but in general it is a bit hard to check for if a socket is closed client side
as for the error im not sure, but it happened in the solution file and the error is Bad file descriptor, might be a bad socket setup if I had to guess?
Well, I think that error message will ALWAYS appear because of the closed connection — see here for more info
In this case all I can advise is to bear with it and add the text "Do not pay attention to STDERR output if it's saying
OSError: [Errno 9] Bad file descriptor
, because that's how the system reacts when the connection is closed" or smth like that to the descriptionThis comment has been hidden.