示例#1
0
    def initUI(self):
        welcome_msg = client.recv()
        self.out_textarea = QtWidgets.QPlainTextEdit(self)
        self.out_textarea.insertPlainText(welcome_msg)
        self.out_textarea.move(OUT_TEXT_X, OUT_TEXT_Y)
        self.out_textarea.resize(OUT_TEXT_W, OUT_TEXT_H)
        self.out_textarea.setReadOnly(True)

        self.in_label = QtWidgets.QLabel(self)
        self.in_label.setText("in:")
        self.in_label.move(IN_LABEL_X, IN_LABEL_Y)

        self.in_textbox = QtWidgets.QLineEdit(self)
        self.in_textbox.move(SEND_TEXT_X, SEND_TEXT_Y)
        self.in_textbox.resize(SEND_TEXT_W, SEND_TEXT_H)

        self.send_button = QtWidgets.QPushButton(self)
        self.send_button.setText("SEND")
        self.send_button.move(SEND_BUTTON_X, SEND_BUTTON_Y)
        # this called signals in PyQt...
        self.send_button.clicked.connect(self.send_clicked)

        self.dissc_button = QtWidgets.QPushButton(self)
        self.dissc_button.setText("dissconnect")
        self.dissc_button.move(DISSC_BUTTON_X, DISSC_BUTTON_Y)
        # this called signals in PyQt...
        self.dissc_button.clicked.connect(self.dissc_clicked)
示例#2
0
    def listening():
        while True:

            msg = client.recv()
            msg = aes128.decrypt_text(msg, encKey)

            rbox.configure(state='normal')
            rbox.insert(END, msg)
            rbox.see('end')
            rbox.configure(state='disabled')
        def client_thread(client, username):

            print("Running client_thread")

            client.send(bytes(room_name, "utf-8"))

            for message in messages:
                print(message)
                client.send(bytes(message, "utf-8"))

            print("Type of username: "******"",
                username.decode("utf-8") + " has entered the chat \n")

            while True:
                try:
                    message = client.recv(2000).decode("utf-8")
                    print(message)
                    print("message received")
                    if message:
                        if message[0:3] == "***":
                            print("command received")
                            action_handler(message[3:])
                        elif username not in mute_list:
                            print("broadcasting message")
                            broadcast_message(username.decode("utf-8"),
                                              message)
                        else:
                            print("poo poo")
                    else:
                        print("Client closed:(")
                        client.close()
                        remove(username)

                except:
                    continue
 def receive(self, client):
     buffer = ""
     while not buffer.endswith(model.END_CHARACTER):
         buffer += client.recv(BUFFER_SIZE).decode(model.TARGET_ENCODING)
     return buffer[:-1]
示例#5
0
def recv_login_data(user,pas):
    temp=client.recv(user,pas)
    data=eval(temp)
    return data
示例#6
0
for i in range(1000):
    sum1 += adc.read_adc(0, gain=GAIN)
    sum2 += adc.read_adc(1, gain=GAIN)
    sum3 += adc.read_adc(2, gain=GAIN)
diff[0] = sum1 / 1000
diff[1] = sum2 / 1000
diff[2] = sum3 / 1000

# Connecting to the server
ip = "138.197.235.123"
print("Connecting to " + ip)
client = socket.socket()
client.connect((ip, 80))
print("Pinging server:")
client.send("ping".encode())
print("Server says: " + client.recv(1024).decode())

# Main loop.
while True:
    # Read all the ADC channel values in a list.
    values = [0] * 3
    for i in range(3):
        # Read the specified ADC channel using the previously set gain value.
        values[i] = adc.read_adc(i, gain=GAIN) - diff[i]
        # Note you can also pass in an optional data_rate parameter that controls
        # the ADC conversion time (in samples/second). Each chip has a different
        # set of allowed data rate values, see datasheet Table 9 config register
        # DR bit values.
        # values[i] = adc.read_adc(i, gain=GAIN, data_rate=128)
        # Each value will be a 12 or 16 bit signed integer value depending on the
        # ADC (ADS1015 = 12-bit, ADS1115 = 16-bit).
示例#7
0
import client
import socket

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
server_addr = ("houlu.me", 8674)

client.recv(s, server_addr)
示例#8
0
if (x == 1):
    val = int(input("input the interval"))
    server.conn(host, port)
    server.send(str(val))
    val = val / 2

    # multiprocessing
    np = multiprocessing.cpu_count()
    print('You have {0:1d} CPUs'.format(np))
    part_count = [int(val / np) for i in range(np)]
    pool = Pool(processes=np)
    cp = pool.map(getpoint, part_count)
    cp = sum(cp)
    print("locally computed", cp)
    server.send(str(cp))

else:
    val = int(client.recv(host, port).split('.')[0])
    print("interval received", val)
    val = val / 2
    np = multiprocessing.cpu_count()
    print('You have {0:1d} CPUs'.format(np))
    part_count = [int(val / np) for i in range(np)]
    pool = Pool(processes=np)
    cp1 = pool.map(getpoint, part_count)
    cp1 = sum(cp1)
    print("locally computed", cp1)
    cp2 = int(client.recv(host, port).split('.')[0])
    print("received", cp2)
    pi = comp(cp1 + cp2, val * 2)
    print(pi)
示例#9
0
        callback 为收到消息时调用的方法,以下做了示例
'''
'''
    示例 channl : collection_channl | view_channl

    发送到 collection_channl 的消息将转发至 view_channl 

    即 collection_channl 负责接收消息 view_channl 负责显示消息
'''

# 发送字符串


import client
client.send('collection_channl', 'please')
# 发送数字
client.send('collection_channl', 144)
# 发送对象
client.send('collection_channl', {'from': 'you', 'to': 'me', 'temp': 123})


def doSomeThing(*args):
    print('recv:', args)


# recv调用示例
client.recv('view_channl', doSomeThing)

# 若想收到消息 务必调用此方法
client.wait()