我在学校的python中做了一个项目,我遇到了一个问题。
我正在尝试连接两台计算机,共享鼠标,键盘,屏幕和音频。一切正常'除了音频。
我正在尝试创建一种对话,因此客户端和服务器需要在整个聊天过程中同时获取和发送音频。问题是我只能使一个连接工作。如果服务器只听aor只发送音频'然后它起作用了#39;但是如果它试图同时做到这两点,那就失败了。
当它失败时,我收到这条消息:
此应用程序已请求Runtime以不寻常的方式终止它。 请联系应用程序的支持团队以获取更多信息。
但之前有效。当我添加gui并更改服务器时问题就开始了。
这是服务器端:
def start_lesson(entry_ip):
entry_ip.focus_set()
my_ip = get_my_ip()
ip_user = entry_ip.get()
if my_ip == ip_user:
tkMessageBox.showinfo("error", "you can not enter your IP")
if is_valid_ipv4_address(my_ip) == False:
tkMessageBox.showinfo("error", "not a valid IP")
else:
pass
my_socket = socket.socket()
my_socket.connect((ip_user, 7002))
msg = "i want to connect with you: " +my_ip
my_socket.send(msg)
my_socket.close()
ip = ip_user
snd_pic = class_lesson.Lesson( ip)
recv_mouse = class_lesson.Lesson(ip)
recv_key = class_lesson.Lesson(ip)
recv_key_thread = threading.Thread(target = recv_key.receive_keyboard)
recv_mouse_thread = threading.Thread(target = recv_mouse.recieve_mouse)
send_pic_thread = threading.Thread(target = snd_pic.send_screenshot)
send_sound_thread = threading.Thread(target = snd_aud, args = (ip, ))
get_sound_thread = threading.Thread(target = recv_aud, args = (ip, ))
recv_mouse_thread.start()
send_pic_thread.start()
recv_key_thread.start()
send_sound_thread.start()
get_sound_thread.start()
def recv_aud(ip):
server_socket = socket.socket()
server_socket.bind(('0.0.0.0',1240))
server_socket.listen(1)
client_socket, addr = server_socket.accept()
print "conntected recv to: " + addr[0]
aud = audio_class.Audio(client_socket)
aud.get_sound()
def snd_aud(ip):
server_socket = socket.socket()
server_socket.bind(('0.0.0.0',1201))
server_socket.listen(1)
client_socket, addr = server_socket.accept()
print "conntected send to: " + addr[0]
aud1 = audio_class.Audio(client_socket)
aud1.send_sound()
客户端看起来与服务器端略有不同。
客户端:
def main():
p0 = Process(target = setgui)
p0.start()
server_socket = socket.socket()
server_socket.bind(('0.0.0.0',7002))
server_socket.listen(1)
client_socket, addr = server_socket.accept()
data, addr = client_socket.recvfrom(1024)
match = re.match('i want to connect with you: \d+\.\d+.\d+\.\d+', data)
if match:
find = re.search('i want to connect with you: (\d+\.\d+.\d+\.\d+)', data)
ip = find.group(1)
client_socket.close()
ip = str(ip)
print ip
p1 = Process(target=scrnshot, args=(ip,))
p2 = Process(target=mouse, args=(ip,))
p3 = Process(target=sndkey, args=(ip, ))
p4 = threading.Thread(target= snd_aud, args = (ip, ))
p5 = threading.Thread(target = recv_aud, args = (ip, ))
p2.start()
p1.start()
p3.start()
p4.start()
p5.start()
def snd_aud(ip):
aud_sock = socket.socket()
aud_sock.connect((ip, 1240))
print "connected send: " + ip
send_audio = audio_class.Audio(aud_sock)
send_audio.send_sound()
def recv_aud(ip):
aud_sock = socket.socket()
aud_sock.connect((ip, 1201))
print "connected recv: " + ip
recv_sound = audio_class.Audio(aud_sock)
recv_sound.get_sound()
感谢所有帮助者。