Solved

Python - Help - This unexpected EOF error is absurd!

Posted on 2014-09-26
2
331 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

A set of related code is known to be a Module, it helps us to organize our code logically which is much easier for us to understand and use it. Module is an object with arbitrarily named attributes which can be used in binding and referencing. …
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 …
Learn the basics of strings in Python: declaration, operations, indices, and slicing. Strings are declared with quotations; for example: s = "string": Strings are immutable.: Strings may be concatenated or multiplied using the addition and multiplic…
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…

867 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now