Sort 25 Discussions, By:
Please Login in order to post a comment
To what port number should be bind the server to ?
I think it is only IP, what is the port number?
Can you provide some helper functions for Java as for C/C++?
I've solved this problem in Java. Please have a look at
Another thing: don't try to write everything at once to the output. Write to the output stream the same quantity of bytes that is being read from the input stream.
Thanks for your helpful hints. The link you posted seems to be broken, but the project is accessible through https://github.com/kohlschutter/junixsocket.
def write_string_to_socket(connection, message):
# read message
message = read_string_from_socket(connection)
print "Message received = ", message
if message == "END":
Python: I had difficulty understanding what it wants me to do.
It simply wants you to define the methods read_string_from_socket, write_string_to_socket to call the appropriate methods on the socket. The socket is created, bound, etc for you and is passed to you as 'connection'.
The same thing (socket.send(), socket.recv(size)) works in Python 2 but not Python 3 - can someone tell me what has changed?
Simplely creating a write_string_to_socket call seems to pass the test without regard to multithreading in C++.
I'm pretty sure this isn't the answer they want, but I'm not sure what the correct answer would look like.
I wanted to mention that it's actually already using pthreads for you in the C++ version. Look at the function layout and the thread exit at the bottom. Without seeing all the code that it doesn't show you it can be confusing!
Bug: Python 3 shows nothing,
Yet Python 2 does provide sufficient hint to complete the answer.
"This challenge tests your understanding of Sockets and Multi-Threaded programming"
If you choose to use C, the only thing you have to do is add the logic to the function
void * process_client_connection(void * ptr)
which will be executed by the threads created when a connection is received. It doesn't really involve any Multi-Threaded programming since you never access variables that could be shared between threads. Or am I missing something?
I'm doing this in C++14
I get following error on client
Traceback (most recent call last):
File "/custom-lA6iT6IrH3LpFHyXDtxY/solution.py", line 66, in <module>
File "/usr/lib/python2.7/threading.py", line 745, in start
thread.error: can't start new thread
When I read string from socket in server I do not get any string. What I might be doing wrong? Could any of you who did in C/C++ share me your solution? Thanks.
Completed the challenge in c++.
It should be noted that all the messages from the clients have header - an unsigned int denoting the length (4byte) of each message and a tail - single char '/r' (0x13).
No multithreading is needed.