Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UnicodeEncodeError: 'decimal' codec can't encode character u'\x00' in position 2: invalid decimal Unicode string #20

Open
SoungHun opened this issue Feb 21, 2018 · 0 comments

Comments

@SoungHun
Copy link

SoungHun commented Feb 21, 2018

Sever code

#-*- coding: utf-8 -*- 
#1번줄 지우지 말것. 한글 입력을 위한 필수 라인임

import socket               # Import socket module 라이브러리 삭제하지마시오
import os		    # filesize 알아내기 위한 라이브러리 삭제하지마시오
import struct
from thread import *
import threading

Path = 'C:\\File\\T_REX_FBX.fbx'
print 'Sever Start'

def getFileSize():
	"""
	파일 사이즈 알아내는 함수
	"""
	#size = os.path.getsize("./Assets/TocusTest00.fbx")
	size = int(os.path.getsize(Path))
	#return c_int(size).value #c 체계의 int 형태로 변환해주는 코드 필요하면 밑의 return 지우고 이 부분을 사용하셈
	return size


def Filethreaded(c):
        size = getFileSize()
        print 'size', size
        c.send(struct.pack("i", size))

        f = open(Path, 'rb')
        print 'File_Sending...'
        l = f.read(5000)
        while (l):
            print 'Sending...'
            c.sendall(l)
            l = f.read(5000)
        f.close()
def Main():
    host = '192.168.0.18'
    port = 10002
    s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    s.bind((host, port))
    print 'socket binded to post', port
    s.listen(5)
    print 'socket is listening'

    c, addr = s.accept()
    print 'Got connection from', addr

    start_new_thread(Filethreaded, (c,))
    s.close()

if __name__ == '__main__':
    Main()


Client code
#-*- coding: utf-8 -*-

from socket import *
import os, sys

HOST = '192.168.0.18'
PORT = 10002
ADDR = (HOST, PORT)
BUFF_SIZE = 5000

clientSocket = socket(AF_INET, SOCK_STREAM)
clientSocket.connect(ADDR)

### serverFile receive ###
serverData = clientSocket.recv(BUFF_SIZE)

serverFile = 'C:\\File\\SocketTest\\SocketTest.fbx'
with open(serverFile, 'wb') as f:
    print("serverFile opened...")
    count = int(int(serverData.decode("utf-8","ignore")) / BUFF_SIZE + 1)
    while count:
        data = clientSocket.recv(BUFF_SIZE)
        f.write(data)
        count -= 1
    f.close()
print("file received complete")

clientSocket.close()
print('connection closed')
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant