?
Solved

Python - Help - This unexpected EOF error is absurd!

Posted on 2014-09-26
2
Medium Priority
?
359 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Here I am using Python IDLE(GUI) to write a simple program and save it, so that we can just execute it in future. Because when we write any program and exit from Python then program that we have written will be lost. So for not losing our program we…
Introduction On September 29, 2012, the Python 3.3.0 was released; nothing extremely unexpected,  yet another, better version of Python. But, if you work in Microsoft Windows, you should notice that the Python Launcher for Windows was introduced wi…
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 …
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…
Suggested Courses
Course of the Month10 days, 8 hours left to enroll

764 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