Getting started with Python sockets and HTTP

Source: Internet
Author: User

Python iterator:

Iterator=iter (obj)

Iterator.next ()

Python functions:

def function (*args):

A tuple list parameter is passed.

def function (**args):

The dictionary list parameter.

Django Time zone settings: setting.py inside the Time_zone=asian/shanghai

PostgreSQL time zone settings: postgres.conf configuration file Modification Time_zone=asian/shanghai

Python Socket module:

Server-side:

Import socket

S=socket.socket (Socket.af_inet,socket. SOCK_STREAM)

S.bind (' 192.168.1.1 ', 80)

S.listen (1)


While True:

Cs,ca=s.accept ()

Print CS.RECV (1024)

Cs.sendall (' reply ')

Cs.close ()


Client:

Import socket

S=socket.socket (Socket.af_inet,socket. SOCK_STREAM)

S.connect (' 192.168.1.1 ', 80)

S.send (' Hello ')

Print S.RECV (1024)

S.close ()

Python http Library:

Import Httplib

Http=httplib. Httpconnection (' itercast.com ', 80)

Http.request (' GET ', '/ask ')

Print Http.getresponse (). Read ()

Http.close ()


Import URLLIB2 (simpler implementation of HTTP,FTP and other protocols)

Opener=urllib2.build_opener ()

F=opener.open (' Http://itercast.com/ask ')

Print F.read ()

F.close ()

Ping linuxcast.net

Finish.

This article is from the "Blue Fin Dolphin" blog, please be sure to keep this source http://likunheng.blog.51cto.com/9527645/1575509

Getting started with Python sockets and HTTP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.