Upgrade to PRO for Only $50/YearโLimited-Time Offer! ๐ฅ
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Python Korea Twisted Study 2013-06-30
Search
Bae KwonHan
July 01, 2013
2
180
Python Korea Twisted Studyย 2013-06-30
Bae KwonHan
July 01, 2013
Tweet
Share
More Decks by Bae KwonHan
See All by Bae KwonHan
PyCon Korea 2017 micropython, led and thermostat
darjeeling
1
410
PyCon KR 2015 python and test
darjeeling
3
1.3k
PyCon.KR 2014 continuous luck and future
darjeeling
1
160
Featured
See All Featured
Why You Should Never Use an ORM
jnunemaker
PRO
61
9.6k
How to Ace a Technical Interview
jacobian
280
24k
Automating Front-end Workflow
addyosmani
1371
200k
Fireside Chat
paigeccino
41
3.7k
Producing Creativity
orderedlist
PRO
348
40k
Scaling GitHub
holman
464
140k
Side Projects
sachag
455
43k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
31
3k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
32
2.7k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
ๅไบบ้็บใฎๅคฑๆใ้ฟใใใคใฑใฆใ่ใๆน / tips for indie hackers
panda_program
122
21k
Building Flexible Design Systems
yeseniaperezcruz
330
39k
Transcript
Twisted for beginners ๋ฐฐ๊ถํ 13๋ 7์ 1์ผ ์์์ผ
๊ฐ์์ ์์ ์์ฒญ๋๋ฆด ์ โข ๊ฐ์๋ฃ ๋์ ์ ๋ถ๋ด๊ฐ์ง ์๋ ๊ธ์ก์ผ๋ก
์ํ๋๊ณณ์ ๊ธฐ๋ถ๋ฅผ ํด์ฃผ์ธ์. โข ๋๊ตฐ๊ฐ Twisted ์ ๋ํด์ ์๋ ค๋ฌ๋ผ๊ณ ํ ๋ฉด ์๋ ค์ฃผ์ธ์. โข ์ด์ฌ์๋ฅผ ์ํ ๊ฐ์์ ๋๋ค. ๊ณ ๊ธ์๋ ์ ๋๊ฒ๋ถํฐ ์์ํฉ๋๋ค. 13๋ 7์ 1์ผ ์์์ผ
์ด ๊ฐ์์ ๋ชฉํ 13๋ 7์ 1์ผ ์์์ผ
์์ผํ๋ก๊ทธ๋๋ฐ์ ์ฝ ๋ค. 13๋ 7์ 1์ผ ์์์ผ
๋ชฉ์ฐจ โข socket programming is? โข socket client / server
โข single socket โข multi thread โข generator โข framework โข gevent โข tornadio โข twisted 13๋ 7์ 1์ผ ์์์ผ
๊ทธ์ ์ .. โข pythonbrew ์ค์น โข twisted ์ค์น๋ฅผ ํฉ์๋ค. 13๋
7์ 1์ผ ์์์ผ
๊ฐ๋ฐ ํ๊ฒฝ ์ ์ โข mac โข xcode โข homebrew โข
ubuntu โข apt-get install build-essential 13๋ 7์ 1์ผ ์์์ผ
pythonbrew โข https://github.com/utahta/pythonbrew 13๋ 7์ 1์ผ ์์์ผ
socket programming โข UDP ( Datagram Sockets ) โข TCP
( Stream Sockets ) โข RAW ( RAW Sockets ) 13๋ 7์ 1์ผ ์์์ผ
์์ผ์ ํน์ฑ โข UDP โข TCP โข RAW 13๋ 7์
1์ผ ์์์ผ
๋คํธ์ํฌ๋ ์ด๋ป๊ฒ ๋ ์ด ์๋๊ฐ? โข ๋ผ์ฐํฐ โข ๋ ธ๋ (
์จ๋ฒ ํด๋ผ์ด์ธํธ ) โข L4 โข Proxy 13๋ 7์ 1์ผ ์์์ผ
network address โข IPV4 โข IPV6 : https://en.wikipedia.org/wiki/IPV6 โข Private
Network โข 10.0.0.0/8 โข 172.16.0.0/12 โข 192.168.0.0/16 13๋ 7์ 1์ผ ์์์ผ
network address โข https://en.wikipedia.org/wiki/IPv4 โข Special USE Addresses 13๋ 7์
1์ผ ์์์ผ
IP Header 13๋ 7์ 1์ผ ์์์ผ
https://en.wikipedia.org/ wiki/IPv4#Header 13๋ 7์ 1์ผ ์์์ผ
โข https://en.wikipedia.org/wiki/ User_Datagram_Protocol UDP 13๋ 7์ 1์ผ ์์์ผ
TCP โข https://en.wikipedia.org/wiki/ Transmission_Control_Protocol 13๋ 7์ 1์ผ ์์์ผ
TCP Header 13๋ 7์ 1์ผ ์์์ผ
13๋ 7์ 1์ผ ์์์ผ
TCP ์ํ๊ฐ ์ด์ฉ๊ณ .. 13๋ 7์ 1์ผ ์์์ผ
์ฐ๋ฆฌ๋ ์ด๋ฐ๊ฑฐ ๋ชฐ๋ผ๋ ๋จ 13๋ 7์ 1์ผ ์์์ผ
โข ์ฐ๊ฒฐ โข ์ฌ์ฉ โข ๋ โข ์๋ฌ ์ด๊ฒ๋ง ์๋ฉด
๋ฉ๋๋ค. 13๋ 7์ 1์ผ ์์์ผ
๊ทธ๋ผ ํ๋์ฉ ์ง๋ด ์ ๋ค. 13๋ 7์ 1์ผ ์์์ผ
์น ํ์ด์ง๋ฅผ ๊ฐ์ ธ์ค๋ ์์ผ ํ๋ก๊ทธ๋๋ฐ 13๋ 7์ 1์ผ ์์์ผ
1 #!/usr/bin/python 2 3 import socket 4 5 s =
socket.socket() 6 s.connect(("ifconfig.me",80)) 7 s.sendall("GET /\n") 8 data = "" 9 while True: 10 buf = s.recv(1024) 11 if buf == "": 12 break 13 else: 14 data += buf 15 s.close() 16 print data 13๋ 7์ 1์ผ ์์์ผ
urllib 13๋ 7์ 1์ผ ์์์ผ
1 #!/usr/bin/python 2 3 import urllib 4 5 print urllib.urlopen("http://ifconfig.me").read()
13๋ 7์ 1์ผ ์์์ผ
๊ทธ๋ฐ๋ฐ ์ง๊ธ๊น์ง์ ๋ฌธ ์ ๋? 13๋ 7์ 1์ผ ์์์ผ
1๋ฒ์ 1๊ฐ๋ง ๋จ 13๋ 7์ 1์ผ ์์์ผ
๊ทธ๋ผ ์จ๋ฒ๋ ์ง๋ด ์ ๋ค. 13๋ 7์ 1์ผ ์์์ผ
1 #!/usr/bin/python 2 3 import socket 4 5 s =
socket.socket() 6 s.bind(("0.0.0.0",9999)) 7 s.listen(1) 8 conn, addr = s.accept() 9 print 'Connected by', addr 10 while 1: 11 data = conn.recv(1024) 12 if not data: break 13 conn.sendall(data) 14 conn.close() 15 13๋ 7์ 1์ผ ์์์ผ
tornado 13๋ 7์ 1์ผ ์์์ผ
http:// www.tornadoweb.org/ en/stable/ 13๋ 7์ 1์ผ ์์์ผ
http://www.tornadoweb.org/ en/stable/ ioloop.html#ioloop-objects 13๋ 7์ 1์ผ ์์์ผ
about twisted 13๋ 7์ 1์ผ ์์์ผ
http:// www.aosabook.org/en/ twisted.html 13๋ 7์ 1์ผ ์์์ผ
โข ์ญ์ฌ โข socket โข protocol โข factory โข process
โข threads โข logging โข application โข callLater / LoopingCall โข database call โข twistd 13๋ 7์ 1์ผ ์์์ผ
โข 2002๋ ์ฒซ ๋ฆด๋ฆฌ์ฆ โข ์ง๊ธ์ 13.0.0 ์ญ์ฌ? 13๋ 7์
1์ผ ์์์ผ
โข Separation of protocols and transports โข Deferreds โข Thread
Support โข Foreign Loop support ํน์ง์ 13๋ 7์ 1์ผ ์์์ผ
socket โข http://twistedmatrix.com/trac/wiki/ FrequentlyAskedQuestions#HowdoImakein putononeconnectionresultinoutputonanoth er 13๋ 7์ 1์ผ ์์์ผ
code examples โข http://twistedmatrix.com/documents/ 13.0.0/core/examples/ 13๋ 7์ 1์ผ ์์์ผ
writing servers โข http://twistedmatrix.com/documents/ 12.2.0/core/howto/servers.html 13๋ 7์ 1์ผ ์์์ผ
run another process โข http://twistedmatrix.com/documents/ 13.0.0/core/howto/process.html 13๋ 7์ 1์ผ ์์์ผ
threads โข http://twistedmatrix.com/documents/ 12.2.0/core/howto/threading.html 13๋ 7์ 1์ผ ์์์ผ
application โข http://twistedmatrix.com/documents/ 12.3.0/core/howto/application.html 13๋ 7์ 1์ผ ์์์ผ
logging โข http://twistedmatrix.com/documents/ 12.2.0/core/howto/logging.html 13๋ 7์ 1์ผ ์์์ผ
callLater โข http://twistedmatrix.com/documents/ 11.0.0/core/howto/time.html 13๋ 7์ 1์ผ ์์์ผ
database โข http://twistedmatrix.com/documents/ 12.2.0/core/howto/rdbms.html 13๋ 7์ 1์ผ ์์์ผ
twistd โข http://www.saltycrane.com/blog/2008/10/ running-twisted-perspective-broker- example-twistd/ 13๋ 7์ 1์ผ ์์์ผ