import socket
import os
import io
import os.path
import tesserocr
from PIL import Image
from mtranslate import translate

def Main():
	s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
	host = ''
	port = 5007
	sum = 0
	s.bind((host, port))

	s.listen(1)
	print("Waiting for a connection...")

	c, addr = s.accept()
	print("Connection from: " + str(addr))

	if os.path.isfile("image.png"):
        	os.remove("image.png")

	file = open("image.png", "w+b")
	while True:
        	data = c.recv(1024)
		if not data:
			break
		file.write(data)
		file.flush()

	print("Image To Text")
	print(tesserocr.file_to_text('image.png'))
	tst = tesserocr.file_to_text('image.png')


	f = open('tess.txt', 'r+')
	f.write(tst.encode('utf-8'))
	f.flush()

	fw = open('trans.txt', 'w')
	
	fdata = f.read()
		
	print("Text English -> Korean")
	print(translate(fdata, 'ko'))
	fdata = translate(fdata, 'ko')	
	fw.write(fdata.encode('utf-8'))
	
	s.send('trans.txt')
	print("Done.")

	c.close()
	s.close()

if __name__ == "__main__":
	Main()

@@ -730,10 +730,9 @@
 ', '
-r+
+w
 ')%0D%0A
@@ -760,16 +760,17 @@
 utf-8'))
+s
 %0D%0A%09f.flu
@@ -770,24 +770,36 @@
 %0A%09f.flush()%0D
+%0A%09f.close()%0D
 %0A%0D%0A%09fw = ope
@@ -820,18 +820,58 @@
  'w')%0D%0A%09
-%0D%0A
+f = open('tess.txt', 'r')%0D%0A%09while True:%0D%0A%09
 %09fdata =
@@ -881,57 +881,50 @@
 read
+line
 ()%0D%0A%09%09
-%0D%0A%09print(%22Text English -%3E Korean%22)%0D%0A%09print(
+if not fdata: break;%0D%0A%09%09fdata = 
 tran
@@ -945,45 +945,27 @@
 ko')
-)
 %0D%0A%09
-fdata = translate(fdata, 'ko')%09
+%09print(fdata)
 %0D%0A
+%09
 %09fw.
@@ -999,30 +999,25 @@
 )%0D%0A%09
-%0D%0A%09s.send('trans.txt')
+%09fw.write('%5Cn')%0D%0A
 %0D%0A%09p

Fix bug