Python Socket.error Errno 22 Invalid Argument
Contents |
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the
Python Socket Bind Invalid Argument
workings and policies of this site About Us Learn more about Stack socket error invalid argument Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions errno 22 invalid argument python Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join
Python Setsockopt
them; it only takes a minute: Sign up Invalid argument exception in socket.accept() if I restart immediately after a previous run quit up vote 5 down vote favorite I have a client server architecture written in python. Most of the time it works fine, but sometimes, after I stop the server and restart it immediately afterwards, I get the
Socket.error: [errno 9] Bad File Descriptor
following error: Accept failed due to : 22 Message Invalid argument, error: [Errno 22] Invalid argument However, if I wait a few minutes and the start the same script again with no changes it works fine. This is the loop I use on the server to accept incoming connections from clients: try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('',port)) s.listen(1) except: #logError() while True: try: conn, address = s.accept() #THIS ACCEPT FAILS SOMETIMES multiprocessing.Process(target=HandleConnection, args=(conn, address, messageQueue, taskQueue, IOLock, numberOfConnections, numberOfConnectionsLock,resultsDirectory)).start() except socket.error, msg: #logError() -> this except catches the error Does the port get blocked for some time after I run the server? If so, is there are way to query if the port is blocked and wait until it's unblocked if I want to start the server up again immediately after it just quit? python sockets share|improve this question asked Feb 13 '13 at 20:43 Alexander 565817 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted You need to set SO_REUSEADDR before binding. setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) Failing to d
here for a quick overview of the site Help Center Detailed answers socket.error: [errno 32] broken pipe to any questions you might have Meta Discuss the
So_reuseaddr
workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the http://stackoverflow.com/questions/14862742/invalid-argument-exception-in-socket-accept-if-i-restart-immediately-after-a-p Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up OSError: [Errno 22] Invalid argument in python3 socket up vote 4 down vote favorite I have a problem with socket programming in Python http://stackoverflow.com/questions/18041735/oserror-errno-22-invalid-argument-in-python3-socket 3. I get an exception that is not making the program crash, but is just shown in terminal. Here is my code: from PyQt4 import QtCore, QtGui from imigui import Ui_MainWindow class imiserv(QtGui.QMainWindow): send_msg = pyqtSignal('QString', 'QString') def __init__(self, parent=None): QtGui.QWidget.__init__(self, parent) self.ui = Ui_MainWindow() self.ui.setupUi(self) self.ui.Sport_lineEdit.setMaxLength(5) self.ui.Sconnect_pushButton.clicked.connect(self.serv) self.send_msg.connect(self.write_msg) def write_msg(self, lbl_msg= None, txt_msg= None): if lbl_msg: self.ui.C_label.setText(lbl_msg) if txt_msg: self.ui.Clog_textEdit.setText(txt_msg) def serv(self): MY_LOCK = threading.Lock() class CountT(threading.Thread): def __init__(self, parent): threading.Thread.__init__(self) self._parent= parent def run(self): MY_LOCK.acquire() self._parent.send_msg.emit("Waiting connections","") while True: cliconn, (addr, remoport)= self._parent.clis.accept() clirecmsg= str(cliconn.recv(1024) self._parent.send_msg.emit("{0}:{1} is connected.".format(addr, remoport), "{0}:{1}".format(addr, remoport) cliconn.close() MY_LOCK.release() try: self.clis= socket.socket(socket.AF_INET, socket.SOCK_STREAM) self.clis.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) clierhost= str(self.ui.Sip_lineEdit.text()) clierport= int(self.ui.Sport_lineEdit.text()) self.clis.bind((clierhost, clierport)) self.clis.listen(5) a= CountT(self) a.daemon= True a.start() except socket.error as err: err= str(err) print(err) And here are the errors that happened decussate (this error show only in linux os): Exception in thread Thread-1: Traceback (most recent call last): File "/usr/lib/python3.3/threadin
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn http://stackoverflow.com/questions/15638214/socket-error-invalid-argument-supplied more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags https://bugs.debian.org/678525 Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 6.2 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Socket.error: Invalid Argument supplied up vote 8 down vote favorite 2 I am learning networking programming and trying to grasp the basics of sockets through this invalid argument example. import socket,sys s = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) MAX = 65535 PORT = 1060 if sys.argv[1:] == ['server']: s.bind(('127.0.0.1',PORT)) print 'Listening at ' , s.getsockname() while True: data,address = s.recvfrom(MAX) print ' The address at ' , address , ' says ' , repr(data) s.sendto('your data was %d bytes' % len(data),address) elif sys.argv[1:] == ['client']: print ' Address before sending ' ,s.getsockname() s.sendto('This is the message',('127.0.0.1',PORT)) print ' Address after sending ' ,s.getsockname() data,address = s.recvfrom(MAX) print ' The errno 22 invalid server at ' , address , ' says ' , repr(data) else: print >> sys.stderr, 'usage: udp_local.py server | client ' However,its throwing up an exception saying the arguments given by getsockname() were invalid specifically on line 22.The code is correct as far as I know.Here's the exception Traceback (most recent call last): File "udp_local.py", line 23, in
for calendarserver is src:calendarserver. Reported by: tobiasbp