connection.client=this;


if( nc == null ){
nc=new NetConnection();
nc.client=this;
nc.addEventListener(NetStatusEvent.NET_STATUS,onstatus);
nc.connect("rtmp://localhost/so",“ve”);
}

今天写测试的时候没有用监听,直接在服务器端appConnect接口写了一个invock()方法

但是在flex客户端一直不能出现想到的调用方法,加上nc.client=this就可以了。。
优化并改编以下代码,使其和原来有部分出入但实现效果相同: 1. import socket 2. 3. 4. def client(): 5. # 创建套接字 6. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 7. # 连接服务器 8. ip = input("Please input the receiver's ipv4 address:") 9. sock.connect((ip, 14000)) 10. # 发送文件名 11. filename = input("Please input the filename:") 12. sock.send(filename.encode()) 13. # 接收服务器返回的消息 14. data = sock.recv(1024) 15. print(data.decode()) 16. # 发送文件内容 17. with open(filename, 'rb') as f: 18. for line in f: 19. sock.send(line)20. print('File has sent successfully') 21. # 关闭套接字 22. sock.close() 23. 24. 25.def server(): 26. # 创建套接字 27. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) 28. # 绑定地址和端口号 29. 30. sock.bind(('', 14000)) 31. # 监听连接请求 32. sock.listen(5) 33. while True: 34. # 接受连接请求 35. conn, addr = sock.accept() 36. print('The connection has been established') 37. # 接收文件名 38. filename = conn.recv(1024).decode() 39. print(filename) 40. # 发送消息到客户端 41. conn.send('Got the file name'.encode()) 42. # 接收文件内容并写入文件 43. with open(filename, 'wb') as f: 44. while True: 45. data = conn.recv(1024) 46. if not data: 47. break 48. f.write(data) 49. print('File has received successfully') 50. # 关闭连接套接字 51. conn.close() 52. 53. 54.if name == 'main': 55. while True: 56. answer = input("This is a simple program relying on the Tc p protocol, \n if you want to send the file," 57. "please input 1, \n if you want to receive the file, please input 2, \n if you want exit, " 58. "please input 0: \n") 59. if answer == '0': 60. break 61. if answer == '1': 4162. client() 63. if answer == '2': 64. server()
05-24
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值