Solved

Python - Help - This unexpected EOF error is absurd!

Posted on 2014-09-26
2
353 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

This article will show the steps for installing Python on Ubuntu Operating System. I have created a virtual machine with Ubuntu Operating system 8.10 and this installing process also works with upgraded version of Ubuntu OS. For installing Py…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 …

695 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