• 4
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

Getting Errno 9: Bad file descriptor in python socket

My code is this:

while 1:
    # Determine whether the server is up or down
    try:
        s.connect((mcip, port))
        s.send(magic)
        data = s.recv(1024)
        s.close()
        print data
    except Exception, e:
        print e
    sleep(60)

It works fine on the first run, but gives me Errno 9 every time after. What am I doing wrong?

BTW,

mcip = "mau5ville.com"
port = 25565
magic = "\xFE"

You're calling connect on the same socket you closed. You can't do that.

As for the docs for close say:

All future operations on the socket object will fail.

Just move the s = socket.socket() (or whatever you have) into the loop. (Or, if you prefer, use create_connection instead of doing it in two steps, which makes this harder to get wrong, as well as meaning you don't have to guess at IPv4 vs. IPv6, etc.)

  • 57
Reply Report

i resolved this problem at the past,

you have to make this before connect again:

    s = socket(AF_INET, SOCK_STREAM)

than continue with:

    s.connect((mcip, port))
    s.send(magic)
    data = s.recv(1024)
    s.close()
    print dat
  • 2
Reply Report

Trending Tags