我正在asp.net中开发一个MVC应用程序,并有一个python文件'clientcheck.py',客户端通过该文件将图像/视频发送到服务器(也用Python编写)。我的问题是,如何将python代码集成到MVC应用程序中。我正在运行Visual Studio 2012。 此外,单独运行时的python代码完全正常。我也安装了IronPython。 真的很感激帮助。我是新来的,所以请不要介意我的问题风格是否符合标准。
import socket,os
import sys
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect(("192.168.1.21", 5050))
k = ' '
size = 1024
while(1):
print ("Do you want to Send a \n1.Image\n2.Video\n")
k = raw_input()
#k=k.encode('utf-8')
client_socket.send(k)
print (k)
k = int (k)
# if(k == 1):
# print ("Enter file name\n")
# data = input()
# data=data.encode('utf-8')
# fp = open(data,'r')
# print ("Opening file - ",data)
# fp = open(data,'r')
# strng = fp.read()
# size = os.path.getsize(data)
# size = str(size)
# client_socket.send(size)
# print ("")
# client_socket.send (strng)
# client_socket.close()
# print ("Data sent successfully")
if (k==1 or k==2):
print ("Enter file name of the image with extentsion (example: filename.jpg,filename.png or if a video file then filename.mpg etc) - ")
fname = raw_input()
fname1 = 'Received_'+fname
fname = """C:/Users/Mehmoo/Desktop/Python/"""+fname
print ("Opening file - ",fname)
#fname1=fname1.encode('utf-8')
client_socket.send(fname1)
img = open(fname,'rb')
while True:
strng = img.read(1024)
print('Sending data...')
if not strng:
break
client_socket.send(strng)
img.close()
print ("Data sent successfully")
exit()