목록프로그래밍 (17)
yongyong-e
SUMMARY문자열에서 중복되는 문자없이 유일한 문자들만 존재하는지 판별하는 함수를 만들어보자. Code# unique_str.py def unique_string(str): if len(str) > 256: return False hash = [False] * 256 for ch in str: if hash[ord(ch)] is True: return False else: hash[ord(ch)] = True return True print('문자열을 입력하세요.') str = input() print(unique_string(str))
SUMMARYpython에서 문자열을 뒤집는 함수를 만들어보자. Code# reverse_str.py # solve_1 def reverse_string(str): return str[::-1] # solve_2 def reverse_stack(str): stack = [] for ch in str: stack.append(ch) result = "" while len(stack) > 0: result += stack.pop() return result print('뒤집을 문자열을 입력하세요.') str = input() print(reverse_stack(str))
threading을 사용하여 여러 클라이언트와 연결이 가능하도록 구현 # Server# serverTest4.py import socket from threading import Thread HOST = socket.gethostname() PORT = 50000 ADDR = (HOST, PORT) BUFF_SIZE = 1024 class ClientThread(Thread): def __init__(self,host,port,sock): Thread.__init__(self) self.host = host self.port = port self.sock = sock print ("(Check the new thread) "+host+":"+str(port)) def run(self): filename=..
local server에서 local client로 파일전송 구현 및 앞선 코드변경 # Server# serverTest3.py import socket HOST = socket.gethostname() PORT = 50000 ADDR = (HOST, PORT) BUFF_SIZE = 1024 serverSocket = socket.socket() serverSocket.bind(ADDR) serverSocket.listen(5) print ('Server waiting...') while True: clientSocket, addr = serverSocket.accept() print ('Connection from', addr) data = clientSocket.recv(BUFF_SIZE) print..
client에서 server로 접속 시 파일전송 구현 # Server# serverTest2.py from socket import * import struct HOST = '192.168.0.10' PORT = 50000 ADDR = (HOST, PORT) BUFF_SIZE = 1024 FILE_NAME = 'clientFile.jpg' FILE_LEN = 0 serverSocket = socket(AF_INET, SOCK_STREAM) serverSocket.bind(ADDR) serverSocket.listen(5) clientSocket, addr = serverSocket.accept() FILE_SIZE = clientSocket.recv(8) FILE_SIZE = struct.unpack('..
# Server# serverTest.py from socket import * HOST = '192.168.0.10' PORT = 50005 ADDR = (HOST, PORT) BUFF_SIZE = 1024 serverSocket = socket(AF_INET, SOCK_STREAM) serverSocket.bind(ADDR) serverSocket.listen(5) clientSocket, addr = serverSocket.accept() client_msg = clientSocket.recv(BUFF_SIZE) print('client : ', client_msg.decode()) server_msg = 'server message' clientSocket.send(server_msg.encode..