0

I'm trying to create a TFTP in python over a existing UDP i have. In my server.py.

As of now I'm able to send requests to read (RRQ) and write (WRQ) to the server. However, then a Packet object (Created object to be sent over to the server) reaches the server, I'm unable to access it.

In server.py :

Packet =  (server_from_client.recv())
print Packet
print id(Packet)
print Packet.opCode

This produces this output :

('127.0.0.1', 53909)
recv done
<Packet.Packet object at 0x1e89f50>


42518000
Traceback (most recent call last):
File "servertest.py", line 16, in <module>
print Packet.opCode
AttributeError: 'str' object has no attribute 'opCode'

Why does it first tell me that it's a Packet.Packet object (which does have an opCode) and then say it's a 'str' object with no opCode ????

Any help will be appreciated.

amankapur91
  • 484
  • 4
  • 15
  • Please paste the code for the `Packet` class. – Eli Bendersky Nov 01 '11 at 06:17
  • My guess is that your `print Packet` statement is what produces the empty lines before the id "42518000" - your recv method actually returns a string. But without seeing the rest of the code that is impossible to say, but obvisoulsy recv does print other stuff, so I guess it prints the thing too. BTW the address printed there 0x1e89f50 is different from the id 42518000 (0x288c5f0), so they are not the same object. – Anders Waldenborg Nov 01 '11 at 09:18

1 Answers1

0

Instead of sending the packet, your client side converts it to the string <Packet.Packet object at 0x1e89f50> and sends it over the wire. Use print type(Packet) and print repr(Packet) to confirm.

anatoly techtonik
  • 19,847
  • 9
  • 124
  • 140