Python side server(socket) | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Python side server(socket)

i trying to write server using python. but the server is sending multiple files like index.html and index.css. so in server.py its send 2 files. but something strange is, the index.css is merged with index.html. here the script: https://code.sololearn.com/WNNnCoLbqWy2/?ref=app https://code.sololearn.com/WTp99Y5GsxgC/?ref=app https://code.sololearn.com/cpJ3D77gI8E1/?ref=app https://code.sololearn.com/c5g32wOCSAG2/?ref=app i try open index.html(offline) and work well, how to fix it?

10th Nov 2017, 12:16 PM
Kevin AS
Kevin AS - avatar
5 Answers
11th Nov 2017, 11:33 AM
Kevin AS
Kevin AS - avatar
+ 1
On line 19 and 20 of your server you send the contents of index.html and index.css back to back. In normal Web server and client communication each page is supposed to be a separate request to the server and therefore a different socket.
10th Nov 2017, 7:56 PM
Kevin Gilkey-Graham
Kevin Gilkey-Graham - avatar
+ 1
thanx for the answer, i will try to experiment. i will tell you my result
11th Nov 2017, 12:23 AM
Kevin AS
Kevin AS - avatar
+ 1
The way you have written the client_handler function it will send both file with any request. You need to write it in such a way that your client program will ask for index.html once, then it should ask again in a separate request for index.css The separate request will be the new socket. What you need to do is figure out what file is being requested in each request. Then have the thread kick off a dynamic client_handler that will only read in the requested file.
11th Nov 2017, 3:38 AM
Kevin Gilkey-Graham
Kevin Gilkey-Graham - avatar
0
im confuse, what diffrent socket? i add some thread again so it will send file, close connection and repeat again. not working. error bad file descriptor. help me please
11th Nov 2017, 1:11 AM
Kevin AS
Kevin AS - avatar