Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Cant get this working, getting Traceback (most recent call last): File \"C:/User

ID: 3890211 • Letter: C

Question

 Cant get this working, getting Traceback (most recent call last):   File "C:/Users/PC/PycharmProjects/untitled3/Prof.py", line 9, in <module>     s.bind(socket.gethostname(), 1550) TypeError: bind() takes exactly one argument (2 given). what am i doing wrong. HELP    import struct import socket  s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Only listen on the local system: #s.bind('127.0.0.1', 1550) s.bind(socket.gethostname(), 1550) s.listen(15)   # open block.dd file as read-binary since it contains binary data f = open("/Users/PC/PycharmProjects/untitled2/block.dd", "rb") blockData = f.read(1024)  # status byte is one byte in size and is located at starting address (0x1BE) statusByte = blockData[0x1BE] # print status byte as hex value (can print as integer too) print("Status Byte = %02x" % statusByte)  # partition type is also one byte and is located at 0x1BE+4 partitionType = blockData[0x1BE+4] # print partition type as hex value as well print("Partition Type = %02x" % partitionType)  # first sector address is four bytes in size according to the table on the wiki page, # so a direct read is not sufficient. we need a four byte range to give to unpack(). # the range is not inclusive, so 0x1BE+8:0x1BE+12 is actually four bytes in size. startAddress = struct.unpack("<i", blockData[0x1BE+8:0x1BE+12]) # return result of unpack() is a tuple, meaning we just want to check the first value in the tuple/list print("Sector address value: %d" % startAddress[0])  len= 2048 while 1:     c, address = s.accept()     data = c.recv(len)     if data:         print(data)     c.close()  import socket  s= socket.socket(socket.AF_INET, socket.SOCK_STREAM)  s.connect('127.0.0.1', 1550) #s.send(someVar) s.send("hi, This is a test message") resp = s.recv(2048) s.close() 

Explanation / Answer

You are passing the wrong number of arguments in "socket.bind()" function on line 7.

As "socket.bind(address)" accepts only the argument "address". So you can pass like following:
s.bind(socket.gethostname()+"1550")

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote