Python Chat Server - 3 - New server code and allowing multiple users via Threading

preview_player
Показать описание

Remember this needs to be formatted properly when copy and pasting!
Source Code:
from socket import *
from threading import Thread

def clientHandler():
print addr, "is Connected"
while 1:
if not data:
break
print "Received Message", repr(data)

HOST = '' #localhost
PORT = 8000

s = socket(AF_INET, SOCK_STREAM)

print "Server is running......"

#Thread(target=clientHandler).start()
#Thread(target=clientHandler).start()
#Thread(target=clientHandler).start()

for i in range(5):
Thread(target=clientHandler).start()

To comment on this video please visit the following:
Рекомендации по теме
Комментарии
Автор

Awesome tuts. I'm a complete noob. I've been through a bunch of beginner tuts and a few intermediate tuts. I was hungry for something other than "hello world" every time I look at a friggin' tut! Thank you so much. Your stuff ROCKS and I really appreciate your teaching style. Kudos dude.

novicetech
Автор

awesome video series. I really appreciate you taking the time to make these. I struggling quite a bit with the basics of sockets before I found this video. keep up the good work.

alexwhb
Автор

Detailing some basics on servers. With threading the server to accept more clients, the server should be able to receive messages from multiple clients until we run out of threads. The issue with the client in chat server 2 is it is built upon server replying back with a response before another message can be sent. To eliminate that, we just take out the statement where we send data. I will quickly make a video tonight explaining that if I didnt explain it right here.

TRUValueInformationSecurity
Автор

I've slowly been working on code and some ideas about how to move on from here. But my purpose of these videos was to try and stay low-level and very basic for demonstration of concepts, or at least for right now. I've ran into the problem of moving any further with this project means getting into some pretty high level coding and high level idea of thought. So Ive been trying to at least find a halfway point between what I have written so far and some of the higher level.

TRUValueInformationSecurity
Автор

Should be under the Python Chat Server playlist as #4

TRUValueInformationSecurity
Автор

h y sir, you have explained very well, but when i'm trying to run this 'chat.py' .it's giving me an errror :
\Local\Programs\Python\Python36\lib\socket.py", line 205, in accept
>>>fd, addr = self._accept()
OSError: [WinError 10038] An operation was attempted on something that is not a socket
however, i have checked my code 4 times but in my case it's not working, so can you tell me,
actually what's happening here .

priyanshgupta
Автор

+SolidShellSecurity at 10:00 the reason it is not doing this time is because you didnt save chat.py after commenting "if not data".

jAYANTYADAVbepositive
Автор

how can i use my socket server from different network or internet pleas help

pkplamps
Автор

Does this only work over LAN? Or will i be requiring to create a website to send data through if i wish to do this over the internet and not just by everyone using 1 modem?

zerker
Автор

The reason why it wouldn't error is because you didn't save it after you commented out the 2 lines. I tested and with those 2 commented out it floods it.

juliettaylorswift
Автор

This not related particularly to this video...but i am really confused about something hoping you might help me with that...so here it goes...how can we make a client talk to other client?? I came accross 'sendto' function but dont know how to use it...

chaitanyasrivastav
Автор

Sweet, thanks! Do you happen to have a Github account?

Abundnce
Автор

Am I supposed to use the same 'cliend.py' file we wrote in Python Chat Server - 2? Because that doesn't function properly (i.e. I can only send one message from each client). Or were you just detailing some basic Python server concepts in this video?

Abundnce
join shbcf.ru