Solved

Python - Help - This unexpected EOF error is absurd!

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Installing Python 2.7.3 version on Windows operating system For installing Python first we need to download Python's latest version from URL" www.python.org " You can also get information on Python scripting language from the above mentioned we…
Flask is a microframework for Python based on Werkzeug and Jinja 2. This requires you to have a good understanding of Python 2.7. Lets install Flask! To install Flask you can use a python repository for libraries tool called pip. Download this f…
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 if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …

743 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

12 Experts available now in Live!

Get 1:1 Help Now