Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #server
- import socket
- import urllib.request
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.bind(('localhost', 9000))
- sock.listen(1)
- conn,addr = sock.accept()
- url = "http://linux.org"
- request = urllib.request.Request(url)
- response = urllib.request.urlopen(request)
- data = response.read().decoding("utf-8")
- conn.send(data)
- conn.close()
- ##################################################################3
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- #client
- import socket
- sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
- sock.connect(('localhost', 9000))
- data = None
- chunk = sock.recv(1024)
- while chunk:
- data += chunk
- chunk = sock.recv(1024)
- sock.close()
- with open("output.txt", "w") as f:
- f.write(data.decode("utf-8"))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement