Solved

Python - Help - This unexpected EOF error is absurd!

Posted on 2014-09-26
2
337 Views
Last Modified: 2014-09-26
Hi

My code below gives an unexpected EOF error, and it says this error is usually associated with spacing. My indentation seems correct. It says the problem is the last line, bit.

I don't know why . . Thanks
?
import socket

class ClientInfo():
    def __init__(self, ip=None, port=None):
        self.ip = ip
        self.port=port








clients = []


# communication packet codes..

MSG_HELO=1

# byte array conversion methods

def intToBytes(n):
    b = bytearray([0, 0, 0, 0])   # init
    b[3] = n & 0xFF
    n >>= 8
    b[2] = n & 0xFF
    n >>= 8
    b[1] = n & 0xFF
    n >>= 8
    b[0] = n & 0xFF    
    
    # Return the result or as bytearray or as bytes (commented out)
    ##return bytes(b)  # uncomment if you need
    return b
    
    
def bytesToInt(b, offset):
    n = (b[offset+0]<<24) + (b[offset+1]<<16) + (b[offset+2]<<8) + b[offset+3]
    return n


###############################



# create an INET, STREAMing socket
serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# bind the socket to a public host, and a well-known port
serversocket.bind((socket.gethostname(), 4321))

# become a server socket

JOIN_BUFFER_SIZE=5
print("listening")
serversocket.listen(5)
waitingForAllClients=True

while waitingForAllClients:
    # accept connections from outside

    print("Deep Red Wars\nServer : Joining Phase . . accept()")
    (clientsocket, address) = serversocket.accept()
    print("TCP joined from : ", address)
    
    print("(TCP recv wait:")
    data = clientsocket.recv(JOIN_BUFFER_SIZE)
    print("TCP received")

    # Analyze msg for joining clients

    print("Msg Type = ")
    print(data[0])

    if data[0] == 1 :
        print("JOIN ")
        clients.append(ClientInfo(address, 8080)

Open in new window

0
Comment
Question by:beavoid
2 Comments
 
LVL 35

Accepted Solution

by:
Robert Schutt earned 500 total points
ID: 40347175
well, I'm not sure if you posted the full code, but as posted, the last line is missing a closing parenthesis:
clients.append(ClientInfo(address, 8080))

Open in new window

0
 

Author Comment

by:beavoid
ID: 40347199
How humiliating ;)

I haven't made that mistake since before CS100.
J++ IDE parentheses balancing has made me complacent!
Thanks
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sequence is something that used to store data in it in very simple words. Let us just create a list first. To create a list first of all we need to give a name to our list which I have taken as “COURSE” followed by equals sign and finally enclosed …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question