Python 3 Programming Tutorial - Sockets: client server system

preview_player
Показать описание
In this Python 3 Programming Tutorial, we cover the use of sockets to pass data around. Here, we have a server, which binds a socket and listens on the port we specify. Then, we are able to use telnet and communicate with our Python script, which takes our data, digests it, and replies.

Bitcoin donations: 1GV7srgR4NJx4vrk7avCmmVQQrqmv87ty6
Рекомендации по теме
Комментарии
Автор

best socket tutorial on the web, I agree with the zero learning documentation on the net. You earned a subscriber!

hopelessdecoy
Автор

+joe jose I know... one day I will be better.

sentdex
Автор

Can you explain why you used threading completely different in this video than in the video where you explained how to use threading? Like you didn't use queues, locks, or daemons and you didn't use start() and join()?

Vagumcookbook
Автор

The theory behind this is all we really need isn't it thank you

Anonymousewizard
Автор

Excellent series, thank you. Would appreciate some videos on ble sockets.

tylersnard
Автор

Seems like telnet works a bit differently on windows 10 than on whatever sendex is using here. It seems to send every keystroke separately. Solved it by changing the code inside the while loop of the threading function to the following

def threaded_client(conn):
conn.send(bytes('welcome type your info\n', 'utf-8'))
reply = ''
while True:
data = conn.recv(2048)
reply = reply + data.decode('utf-8')
if not data:
print('someone left')
break

if data.decode('utf-8') == '\r\n':
output: '+reply))
reply = ''
conn.close()

The change is that it adds every keystroke (data) it receives to the reply, then if the data becomes \r\n (which happens when you press enter) it sends the combined reply and sets the reply to an empty string.

A bit confused as to why you use the _thread module instead of the threading module.

Achmedsander
Автор

can we do this using WIFI connection???
could u please make a video on this subject

shoumoditya_biswas
Автор

thank you. Nice video. On your last note on any specific request - file transfers over socket from a remote host.

Grupapa
Автор

Couple of questions, "if not data:" - when I send a message, after it has received and processed the entire message, how come it doesn't break after and close the connection? we are able to send another message and another, etc... I'm confused why it doesn't break after the first message.

Second, I'm wondering the purpose of sendall instead of send? I'm sure there is a reason for this, just curious why...

discoveringmypath
Автор

Could you make a tutorial about how to make an actual chat server with multiple users. So for example the user will type his name and the ip of the server then he will connect to the server with the name(nickname) that he chose, and the client will be able to talk to others and receive data from other clients. So basic chat server.

xDamix
Автор

I get this error:

client.py
Traceback (most recent call last):
File "my file", line 9, in <module>
s.connect((host, port))
ConnectionRefusedError: [WinError 10061] No connection could be made because the target machine actively refused it

ringingstrings
Автор

I have the following problem:

When running the code I get this output for every char ("a" for example):
aServer  output: a

kommentiererei
Автор

This reall good, you solve my problem, about not close automatically connection.
Thanks a lot.

carlomagno
Автор

Hey good tutorial! Plz make client script.

okidokiokidoki
Автор

When i run client.py in my another pc, faicing connection refused error please help me

bangarurajuraju
Автор

Sentdex - another excellent tutorial. Thanks.

frankahinojosa
Автор

python 2.x no module named _thread... :- ( how can I get it to work in 2.7x?

DariuszMakowski
Автор

Hey, just finished your tutorial series.  Excellent series I might add; the sockets and threaded port scanner were a sweet way to wrap up and I got through this whole series with almost no hiccups.  Im wondering what to do next.  I feel like youve held my hand through this intro to py3 programming and now Im lost as to how to specialize.  I will hit up your flask tutorial, but what after that?  I dont know if you have time or energy to start an intermediate series or advanced but you're such a good teacher I could learn from you indefinitely.  All of us students want to pick your brain.  Anyways thanks a bunch if you have any advice or suggestions Id appreciate it, I think I want to dabble with flask web dev and web apps or services.  Will be sending some btc donation your way for the help sir. 

(ps;. other people mentioned an issue in win7 telnet for this tutorial on how it outputs after every character typed, was curious if you know a solution) 

happy new year and keep up the excellent work man you are a genius

themolynator
Автор

hey i want to know that other than telnet .. how can i connect to server ..can you show me the client side code

chiragsharma
Автор

can you separete what part is the client and what part is the server? i'm really new to this. and it would be mutch easy to see separeted the 2 parts. so i could haver client in one side and server on the other.
thanks and great videos. congrats

PedroMendes