##// END OF EJS Templates
Fedora 10 no deja instalar modulo tftp
imanay -
r41:42
parent child
Show More
@@ -1,200 +1,200
1 import tftpy No newline at end of file
1 #import tftpy No newline at end of file
2 import socket No newline at end of file
2 import socket
3 No newline at end of file
3
4 class UDPServer: No newline at end of file
4 class UDPServer:
5 No newline at end of file
5
6 buf = 16384 No newline at end of file
6 buf = 16384
7 #buf = 1024 No newline at end of file
7 #buf = 1024
8 No newline at end of file
8
9 def __init__(self, port): No newline at end of file
9 def __init__(self, port):
10 # Set the socket parameters No newline at end of file
10 # Set the socket parameters
11 host = "192.168.1.255" No newline at end of file
11 host = "192.168.1.255"
12 #host = "localhost" No newline at end of file
12 #host = "localhost"
13 self.addr = (host,port) No newline at end of file
13 self.addr = (host,port)
14 self.createObjects() No newline at end of file
14 self.createObjects()
15 No newline at end of file
15
16 def createObjects(self): No newline at end of file
16 def createObjects(self):
17 No newline at end of file
17
18 # Create socket and bind to address No newline at end of file
18 # Create socket and bind to address
19 self.sock_s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,0) No newline at end of file
19 self.sock_s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,0)
20 self.sock_s.bind(self.addr) No newline at end of file
20 self.sock_s.bind(self.addr)
21 No newline at end of file
21
22 def listen(self,mode): No newline at end of file
22 def listen(self,mode):
23 No newline at end of file
23
24 # Receive messages No newline at end of file
24 # Receive messages
25 print "Central Control initialized ...with UDP" No newline at end of file
25 print "Central Control initialized ...with UDP"
26 print No newline at end of file
26 print
27 if mode == 0: No newline at end of file
27 if mode == 0:
28 while 1: No newline at end of file
28 while 1:
29 data_rx, add = self.sock_s.recvfrom(self.buf) No newline at end of file
29 data_rx, add = self.sock_s.recvfrom(self.buf)
30 if not data_rx: No newline at end of file
30 if not data_rx:
31 print "Client has exited!" No newline at end of file
31 print "Client has exited!"
32 break No newline at end of file
32 break
33 No newline at end of file
33
34 print "\nCentral Control:" No newline at end of file
34 print "\nCentral Control:"
35 print "Received message '", data_rx,"'" No newline at end of file
35 print "Received message '", data_rx,"'"
36 #print "Sendinf ack ..." No newline at end of file
36 #print "Sendinf ack ..."
37 #self.sock_s.sendto('ack', addr_rx) No newline at end of file
37 #self.sock_s.sendto('ack', addr_rx)
38 else: No newline at end of file
38 else:
39 data_rx, add = self.sock_s.recvfrom(self.buf) No newline at end of file
39 data_rx, add = self.sock_s.recvfrom(self.buf)
40 print "\nCentral Control:" No newline at end of file
40 print "\nCentral Control:"
41 print "Received message '", data_rx,"'" No newline at end of file
41 print "Received message '", data_rx,"'"
42 No newline at end of file
42
43 # Close socket No newline at end of file
43 # Close socket
44 self.sock_s.close() No newline at end of file
44 self.sock_s.close()
45 print "\nsocket closed" No newline at end of file
45 print "\nsocket closed"
46 return data_rx No newline at end of file
46 return data_rx
47 No newline at end of file
47
48 class UDPClient: No newline at end of file
48 class UDPClient:
49 No newline at end of file
49
50 buf = 1024 No newline at end of file
50 buf = 1024
51 No newline at end of file
51
52 def __init__(self, port): No newline at end of file
52 def __init__(self, port):
53 # Set the socket parameters No newline at end of file
53 # Set the socket parameters
54 host = "192.168.1.255" No newline at end of file
54 host = "192.168.1.255"
55 self.multicast_addr = (host,port) No newline at end of file
55 self.multicast_addr = (host,port)
56 self.createObjects() No newline at end of file
56 self.createObjects()
57 No newline at end of file
57
58 def createObjects(self): No newline at end of file
58 def createObjects(self):
59 No newline at end of file
59
60 # Create socket No newline at end of file
60 # Create socket
61 self.socket_c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,0) No newline at end of file
61 self.socket_c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,0)
62 #if self.socket_c == -1: No newline at end of file
62 #if self.socket_c == -1:
63 # print "No se pudo establecer conexion con el socket" No newline at end of file
63 # print "No se pudo establecer conexion con el socket"
64 No newline at end of file
64
65 #self.socket_c.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 20) No newline at end of file
65 #self.socket_c.setsockopt(socket.IPPROTO_IP, socket.IP_MULTICAST_TTL, 20)
66 self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) No newline at end of file
66 self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
67 No newline at end of file
67
68 No newline at end of file
68
69 No newline at end of file
69
70 def sendData(self,TxFrame): No newline at end of file
70 def sendData(self,TxFrame):
71 No newline at end of file
71
72 # Send messages No newline at end of file
72 # Send messages
73 if(self.socket_c.sendto(TxFrame, self.multicast_addr)): No newline at end of file
73 if(self.socket_c.sendto(TxFrame, self.multicast_addr)):
74 print "Sending message:[" + TxFrame + "]" No newline at end of file
74 print "Sending message:[" + TxFrame + "]"
75 No newline at end of file
75
76 data_rx, server_rx = self.socket_c.recvfrom(16) No newline at end of file
76 data_rx, server_rx = self.socket_c.recvfrom(16)
77 No newline at end of file
77
78 print "Data received ", data_rx, server_rx No newline at end of file
78 print "Data received ", data_rx, server_rx
79 No newline at end of file
79
80 # Close socket No newline at end of file
80 # Close socket
81 self.socket_c.close() No newline at end of file
81 self.socket_c.close()
82 No newline at end of file
82
83 class UDPComm: No newline at end of file
83 class UDPComm:
84 No newline at end of file
84
85 __HEADER = "ABS" No newline at end of file
85 __HEADER = "ABS"
86 No newline at end of file
86
87 def __init__(self, ipSource, ipDestino, portDestino, asServer=False): No newline at end of file
87 def __init__(self, ipSource, ipDestino, portDestino, asServer=False):
88 No newline at end of file
88
89 self.ipSource = ipSource No newline at end of file
89 self.ipSource = ipSource
90 self.ipDestino = ipDestino No newline at end of file
90 self.ipDestino = ipDestino
91 self.portDestino = portDestino No newline at end of file
91 self.portDestino = portDestino
92 self.addr = (ipDestino,portDestino) No newline at end of file
92 self.addr = (ipDestino,portDestino)
93 No newline at end of file
93
94 self.openSocket(asServer) No newline at end of file
94 self.openSocket(asServer)
95 No newline at end of file
95
96 def openSocket(self, asServer): No newline at end of file
96 def openSocket(self, asServer):
97 No newline at end of file
97
98 #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM) No newline at end of file
98 #self.socket_c = socket.socket(AF_INET,SOCK_DGRAM)
99 self.socket_c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,0) No newline at end of file
99 self.socket_c = socket.socket(socket.AF_INET, socket.SOCK_DGRAM,0)
100 # self.socket_c.connect((self.ipDestino, self.portDestino)) No newline at end of file
100 # self.socket_c.connect((self.ipDestino, self.portDestino))
101 No newline at end of file
101
102 if asServer: No newline at end of file
102 if asServer:
103 self.configAsServer() No newline at end of file
103 self.configAsServer()
104 else: No newline at end of file
104 else:
105 self.configAsClient() No newline at end of file
105 self.configAsClient()
106 No newline at end of file
106
107 def configAsClient(self): No newline at end of file
107 def configAsClient(self):
108 #Configurar broadcast No newline at end of file
108 #Configurar broadcast
109 self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) No newline at end of file
109 self.socket_c.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
110 No newline at end of file
110
111 def configAsServer(self): No newline at end of file
111 def configAsServer(self):
112 No newline at end of file
112
113 self.socket_c.bind(self.addr) No newline at end of file
113 self.socket_c.bind(self.addr)
114 print "\nServer initialized" No newline at end of file
114 print "\nServer initialized"
115 No newline at end of file
115
116 def waitRequest(self, nbytes): No newline at end of file
116 def waitRequest(self, nbytes):
117 No newline at end of file
117
118 trama_rx, add = self.socket_c.recvfrom(nbytes) No newline at end of file
118 trama_rx, add = self.socket_c.recvfrom(nbytes)
119 print "\nServer has received a data" No newline at end of file
119 print "\nServer has received a data"
120 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) No newline at end of file
120 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx)
121 No newline at end of file
121
122 return ipSource, ipDestino, cmd, data No newline at end of file
122 return ipSource, ipDestino, cmd, data
123 No newline at end of file
123
124 def sendData(self,TxFrame): No newline at end of file
124 def sendData(self,TxFrame):
125 No newline at end of file
125
126 # Send messages No newline at end of file
126 # Send messages
127 if(self.socket_c.sendto(TxFrame, self.addr)): No newline at end of file
127 if(self.socket_c.sendto(TxFrame, self.addr)):
128 print "Sending message:[" + TxFrame + "]" No newline at end of file
128 print "Sending message:[" + TxFrame + "]"
129
129
No newline at end of file
130 # data_rx, server_rx = self.socket_c.recvfrom(16)
130 data_rx, server_rx = self.socket_c.recvfrom(16)
No newline at end of file
No newline at end of file
131 #
131
No newline at end of file
No newline at end of file
132 # print "Data received ", data_rx, server_rx No newline at end of file
132 print "Data received ", data_rx, server_rx No newline at end of file
133 No newline at end of file
133
134 # Close socket
134 # Close socket
No newline at end of file
135 #self.socket_c.close() No newline at end of file
135 self.socket_c.close() No newline at end of file
136 No newline at end of file
136
137 def sendTxRxCommand(self, cmd, data, nbytes = 16384): No newline at end of file
137 def sendTxRxCommand(self, cmd, data, nbytes = 16384):
138 No newline at end of file
138
139 self.sendRequest(cmd, data) No newline at end of file
139 self.sendRequest(cmd, data)
140 No newline at end of file
140
141 #time.sleep(1) No newline at end of file
141 #time.sleep(1)
142 No newline at end of file
142
143 # ipSource_rx, ipDestino_rx, cmd_rx, data_rx = self.getRpta(nbytes) No newline at end of file
143 # ipSource_rx, ipDestino_rx, cmd_rx, data_rx = self.getRpta(nbytes)
144 No newline at end of file
144
145 # if not(self.ipSource == ipDestino_rx): No newline at end of file
145 # if not(self.ipSource == ipDestino_rx):
146 # print "Error" No newline at end of file
146 # print "Error"
147 No newline at end of file
147
148 # return data_rx No newline at end of file
148 # return data_rx
149 No newline at end of file
149
150 def sendRequest(self, cmd, data): No newline at end of file
150 def sendRequest(self, cmd, data):
151 No newline at end of file
151
152 trama_tx = self.__HEADER + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(cmd) + ":" + str(data) + ":" No newline at end of file
152 trama_tx = self.__HEADER + ":" + str(self.ipSource) + ":" + str(self.ipDestino) + ":" + str(cmd) + ":" + str(data) + ":"
153 #self.socket_c.send(trama_tx) No newline at end of file
153 #self.socket_c.send(trama_tx)
154 # Send messages No newline at end of file
154 # Send messages
155 if(self.socket_c.sendto(trama_tx, self.addr)): No newline at end of file
155 if(self.socket_c.sendto(trama_tx, self.addr)):
156 print "Sending message:[" + trama_tx + "]" No newline at end of file
156 print "Sending message:[" + trama_tx + "]"
157 No newline at end of file
157
158 No newline at end of file
158
159 def getRpta(self, nbytes): No newline at end of file
159 def getRpta(self, nbytes):
160 No newline at end of file
160
161 trama_rx = self.socket_c.recv(nbytes) No newline at end of file
161 trama_rx = self.socket_c.recv(nbytes)
162 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx) No newline at end of file
162 ipSource, ipDestino, cmd, data = self.__getTrama(trama_rx)
163 No newline at end of file
163
164 return ipSource, ipDestino, cmd, data No newline at end of file
164 return ipSource, ipDestino, cmd, data
165 No newline at end of file
165
166 def __getTrama(self, trama): No newline at end of file
166 def __getTrama(self, trama):
167 No newline at end of file
167
168 FrameList = trama.split(':') No newline at end of file
168 FrameList = trama.split(':')
169 No newline at end of file
169
170 header = FrameList[0] No newline at end of file
170 header = FrameList[0]
171 ipSource = FrameList[1] No newline at end of file
171 ipSource = FrameList[1]
172 ipDestino = FrameList[2] No newline at end of file
172 ipDestino = FrameList[2]
173 cmd = FrameList[3] No newline at end of file
173 cmd = FrameList[3]
174 data = FrameList[4] No newline at end of file
174 data = FrameList[4]
175 trash = FrameList[5] No newline at end of file
175 trash = FrameList[5]
176 No newline at end of file
176
177 return ipSource, ipDestino, cmd, data No newline at end of file
177 return ipSource, ipDestino, cmd, data
178
178
No newline at end of file
179 #class FTPComm:
179 class FTPComm:
No newline at end of file
No newline at end of file
180 #
180
No newline at end of file
No newline at end of file
181 # ftp_servidor = 'ftp.servidor.com'
181 ftp_servidor = 'ftp.servidor.com'
No newline at end of file
No newline at end of file
182 # ftp_usuario = 'miusuario'
182 ftp_usuario = 'miusuario'
No newline at end of file
No newline at end of file
183 # ftp_clave = 'miclave'
183 ftp_clave = 'miclave'
No newline at end of file
No newline at end of file
184 # ftp_raiz = '/public_html'
184 ftp_raiz = '/public_html'
No newline at end of file
No newline at end of file
185 #
185
No newline at end of file
No newline at end of file
186 # def __init__(self):
186 def __init__(self):
No newline at end of file
No newline at end of file
187 #
187
No newline at end of file
No newline at end of file
188 # self.client = tftpy.TftpClient(self.ftp_servidor, '69')
188 self.client = tftpy.TftpClient(self.ftp_servidor, '69')
No newline at end of file
No newline at end of file
189 #
189
No newline at end of file
No newline at end of file
190 #
190
No newline at end of file
No newline at end of file
191 # def sendFile(self, filename):
191 def sendFile(self, filename):
No newline at end of file
No newline at end of file
192 #
192
No newline at end of file
No newline at end of file
193 # self.client.upload(filename)
193 self.client.upload(filename)
No newline at end of file
No newline at end of file
194 #
194
No newline at end of file
No newline at end of file
195 #if __name__ == '__main__':
195 if __name__ == '__main__':
No newline at end of file
No newline at end of file
196 #
196
No newline at end of file
No newline at end of file
197 # obj = FTPComm()
197 obj = FTPComm()
No newline at end of file
No newline at end of file
198
198
No newline at end of file
No newline at end of file
199
199
No newline at end of file
No newline at end of file
200 No newline at end of file
200 No newline at end of file
General Comments 0
You need to be logged in to leave comments. Login now