代码拉取完成,页面将自动刷新
同步操作将从 计算机网络课程设计/pyqt5socket实现CS通信 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file '1.ui'
#
# Created by: PyQt5 UI code generator 5.6
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
from server import Tcp, Udp
import threading
from server import get_host_ip
class Ui_mainWindow(QtWidgets.QMainWindow):
def __init__(self):
super(Ui_mainWindow,self).__init__()
self.setupUi(self)
self.retranslateUi(self)
def setupUi(self, mainWindow):
mainWindow.setObjectName("mainWindow")
mainWindow.resize(765, 600)
mainWindow.setAutoFillBackground(False)
mainWindow.setAnimated(False)
self.centralwidget = QtWidgets.QWidget(mainWindow)
self.centralwidget.setObjectName("centralwidget")
# self.tcp = Tcp()
self.send = QtWidgets.QTextBrowser(self.centralwidget)
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.rec = QtWidgets.QTextBrowser(self.centralwidget)
self.label = QtWidgets.QLabel(self.centralwidget)
self.tcp_udp = QtWidgets.QPushButton(self.centralwidget)
self.startBtn = QtWidgets.QPushButton(self.centralwidget)
self.ip = QtWidgets.QLabel(self.centralwidget)
self.state = QtWidgets.QLabel(self.centralwidget)
# self.button = QtWidgets.QPushButton(self.centralwidget)
# self.button.setGeometry(QtCore.QRect(210, 50, 94, 32))
# self.button.setObjectName("button")
# self.button.clicked.connect(self.btnclick)
#
# self.button2 = QtWidgets.QPushButton(self.centralwidget)
# self.button2.setGeometry(QtCore.QRect(300, 50, 94, 32))
# self.button2.setObjectName("button2")
# self.button2.clicked.connect(self.end)
self.tcp_udp.setGeometry(QtCore.QRect(210, 40, 94, 32))
self.tcp_udp.setObjectName("button")
self.tcp_udp.setCheckable(True)
self.startBtn.setCheckable(True)
self.protocol = 1 # 设定1为tcp 0为udp
self.tcp = Tcp()
self.udp = Udp()
self.startBtn.setGeometry(QtCore.QRect(310, 40, 94, 32))
self.tcp_udp.clicked[bool].connect(self.btnclick)
self.startBtn.clicked[bool].connect(self.btnclick)
self.ip.setGeometry(QtCore.QRect(230, 80, 120, 20))
self.state.setGeometry(QtCore.QRect(500, 60, 200, 20))
self.state.setObjectName("state")
self.label.setGeometry(QtCore.QRect(350, 130, 91, 31))
font = QtGui.QFont()
font.setPointSize(16)
self.label.setFont(font)
self.label.setObjectName("label")
self.rec.setGeometry(QtCore.QRect(180, 180, 421, 61))
self.rec.setObjectName("rec")
self.label_2.setGeometry(QtCore.QRect(350, 260, 101, 31))
font = QtGui.QFont()
font.setPointSize(16)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.send.setGeometry(QtCore.QRect(180, 310, 421, 151))
self.send.setObjectName("send")
mainWindow.setCentralWidget(self.centralwidget)
self.tcp.state_signal.connect(self.setState)
self.tcp.recv_signal.connect(self.setRec)
self.tcp.send_signal.connect(self.setSend)
self.udp.state_signal.connect(self.setState)
self.udp.recv_signal.connect(self.setRec)
self.udp.send_signal.connect(self.setSend)
self.retranslateUi(mainWindow)
QtCore.QMetaObject.connectSlotsByName(mainWindow)
def retranslateUi(self, mainWindow):
_translate = QtCore.QCoreApplication.translate
mainWindow.setWindowTitle(_translate("mainWindow", "服务器"))
self.tcp_udp.setText(_translate("mainWindow", "当前为tcp协议"))
self.startBtn.setText(_translate("mainWindow", "开始"))
self.state.setText(_translate("mainWindow", "未运行"))
self.rec.setText(_translate("mainWindow", "接收数据"))
self.send.setText(_translate("mainWindow", "发送数据"))
self.label.setText(_translate("mainWindow", "接收信息"))
self.label_2.setText(_translate("mainWindow", "发送信息"))
self.ip.setText(_translate("mainWindow", "{}: {}".format(get_host_ip(), self.tcp.port)))
def setState(self, s):
self.state.setText(s)
def setRec(self, s):
self.rec.setText(s)
def setSend(self, s):
self.send.setText(s)
# def btnclick(self, press):
# # if press:
# # self.button.setText("结束")
# # self.state.setText("已运行")
# # self.rec.setText("准备接收")
# # self.send.setText("等待发送")
# # try:
# # self.th = threading.Thread(target=self.serverThread)
# # self.th.start()
# # print(self.th.getName())
# # except e:
# # print(str(e))
# # pass
# # else:
# # self.button.setText("开始")
# # self.state.setText("终止")
# # print(self.th.getName()) #不做处理线程仍然存在
# # try:
# #
# # except:
# # pass
#
# # def serverThread(self):
# # while True:
# # try:
# # print("进入连接")
# # conn, addr = self.tcp.s.accept()
# # print("已连接,", addr)
# # conn.setblocking(False)
# #
# # self.state.setText("已连接{}:{}".format(addr[0], addr[1]))
# #
# # client_data = conn.recv(1024).decode('utf-8')
# # print("tcp clientdata", client_data)
# # self.rec.setText(client_data)
# # # 这里默认是tcp协议
# #
# # # 发送数据
# # print("发送数据")
# # msg = self.tcp.getmsg()
# # # self.rec.setText(msg)
# # conn.sendall(msg.encode('utf-8'))
# #
# # conn.close()
# # except e:
# # print(str(e))
# # pass
# if press:
# self.button.setText("结束")
# self.state.setText("服务器已运行")
# self.tcp.start()
# else:
# self.button.setText("开始")
# self.state.setText("断开连接")
# print(self.tcp.currentThread())
# self.tcp.terminate()
# print(self.tcp.currentThread())
def btnclick(self, press):
sender = self.sender()
if sender == self.tcp_udp:
if press:
self.tcp.terminate()
self.tcp_udp.setText("当前为udp协议")
self.startBtn.setText("已停止")
self.protocol = 0
else:
self.udp.terminate()
self.tcp_udp.setText("当前为tcp协议")
self.startBtn.setText("已停止")
self.protocol = 1
elif sender == self.startBtn:
if press:
self.startBtn.setText("结束")
if self.protocol == 1: # tcp
print("tcp开始")
self.state.setText("服务器正在运行tcp协议")
self.ip.setText("{}:{}".format(self.tcp.ip_port[0], self.tcp.ip_port[1]))
self.tcp.start()
else:
print("udp开始")
self.state.setText("服务器正在运行udp协议")
self.ip.setText("{}:{}".format(self.udp.ip_port[0], self.udp.ip_port[1]))
self.udp.start()
else:
self.startBtn.setText("开始")
if self.protocol == 1:
print("tcp结束")
pass
# self.tcp.terminate()
else:
print("udp结束")
pass
# self.udp.terminate()
self.state.setText("断开连接")
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。