본문 바로가기
프로그래밍/Python

Python Socket example

by 즉흥 2016. 9. 17.
728x90
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import socket
HOST = 'test.kr'
PORT = 8000
 
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((HOST,PORT))
 
data = s.recv(1024)
print data
 
s.send("5000" + '\n')
data = s.recv(1024)
print data
 
 
s.close()
cs



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import socket
 
HOST = '127.0.0.1'
PORT = 9999
 
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
 
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind((HOST, PORT))
server_socket.listen()
 
client_socket, addr = server_socket.accept()
 
print('Connected by', addr)
 
while True:
 
    data = client_socket.recv(1024)
 
    if not data:
        break
 
    print('Received from', addr, data.decode())
 
    client_socket.sendall(data)
 
client_socket.close()
server_socket.close()
cs



https://webnautes.tistory.com/1381

.

728x90
반응형

'프로그래밍 > Python' 카테고리의 다른 글

python simple reflector server  (0) 2023.01.05
how to get pid  (0) 2019.01.30
Python telnetlib  (0) 2017.05.10
Python GetProcAddress  (4) 2017.02.23
python Convert list to ascii  (0) 2016.07.05

댓글