Пример #1
0
    def send(self, target, message):
        if target == self.id:
            return

        conn = Client((ADDRESS, PORT + target))

        try:
            conn.connect((ADDRESS, PORT + target))
            data = {'id': self.id, 'clock': self.clock, 'message': message}

            conn.send(data)
            conn.close()
        except:
            self.print(f"Falha ao comunicar com o processo {target}")
            if target in self.alive_list:
                self.alive_list.remove(target)
                if target == self.leader[1]:
                    self.print(f"Líder caiu.")
Пример #2
0
s = socket(AF_INET, SOCK_STREAM)
s.bind( ('', 25000))
s.listen(1)
c, a = s.accept()

#after client connected
import numpy
a = numpy.arange(0.0, 50000000.0)
send_from(a, c)


#client 

from socket import *
c = socket(AF_INET, SOCK_STREAM)
c.connect( ('localhost', 25000))

import numpy
a = numpy.zeros( shape = 50000000, dtype = float)
a[0:10]
#array([ 0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.,  0.])
recv_into(a, c)
a[0:10]
#array([ 0.,  1.,  2.,  3.,  4.,  5.,  6.,  7.,  8.,  9.])