I'm trying to make something that once it is disconnected will
automatically try to reconnect. I'll add some more features in later so
it doesn't hammer the server but right now I just want to keep it simple
and get that part working. The problem is that when I use sock.close I
get an error message of
Bad File Descriptor
and if I either use shutdown or just go straight to reconnecting I get:
Transport endpoint is already connected
This is what I've got right now:
#! /usr/bin/env python
import socket, string
sock = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
def doconn():
sock.connect((" localhost", 1234))
def dodiscon():
sock.close()
doconn()
doconn()
while (1):
buffer = sock.recv(1024)
if not buffer:
dodiscon() 3 8449
Did you try just creating a new socket every time you do a connect ?
On Mar 28, 10:01 am, Jason Kristoff <deevine-removethis-
s...@gmail.comw rote:
I'm trying to make something that once it is disconnected will
automatically try to reconnect. I'll add some more features in later so
it doesn't hammer the server but right now I just want to keep it simple
and get that part working. The problem is that when I use sock.close I
get an error message of
Bad File Descriptor
and if I either use shutdown or just go straight to reconnecting I get:
Transport endpoint is already connected
This is what I've got right now:
#! /usr/bin/env python
import socket, string
sock = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
def doconn():
sock.connect((" localhost", 1234))
def dodiscon():
sock.close()
doconn()
doconn()
while (1):
buffer = sock.recv(1024)
if not buffer:
dodiscon()
This is what I've got right now:
#! /usr/bin/env python
import socket, string
sock = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
def doconn():
sock.connect((" localhost", 1234))
def dodiscon():
sock.close()
doconn()
doconn()
while (1):
buffer = sock.recv(1024)
if not buffer:
dodiscon()
sock.recv(1024) can return zero bytes of data indicating that no data
arrived yet. It does not mean that you have been disconnected. This is
especially true when you do nothing but recv, recv, recv() in an
infinite loop.
I recommend that you use select.select to see if there is some data that
can be read. Call socket.recv() only when you know that it will not fail.
Best,
Laszlo
On Mar 28, 10:01 am, Jason Kristoff <deevine-removethis-
s...@gmail.comw rote:
I'm trying to make something that once it is disconnected will
automatically try to reconnect. I'll add some more features in later so
it doesn't hammer the server but right now I just want to keep it simple
and get that part working. The problem is that when I use sock.close I
get an error message of
Bad File Descriptor
and if I either use shutdown or just go straight to reconnecting I get:
Transport endpoint is already connected
This is what I've got right now:
#! /usr/bin/env python
import socket, string
sock = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
def doconn():
sock.connect((" localhost", 1234))
def dodiscon():
sock.close()
doconn()
doconn()
while (1):
buffer = sock.recv(1024)
if not buffer:
dodiscon()
I'd recommend to look at Twisted ReconnectingCli entFactory - http://twistedmatrix.com/trac/browse...otocol.py#L198 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: James Yang |
last post by:
Hi,
I am using Sockets to connect to a remote computer and send data using
Socket.Send() and receive using Socket.Receive() (block mode) . for
somereason tho, when the client disconnects the Socket.Receive() just passes
without any exception. Is there any way to detect disconnection using
Sockets?
I believe I saw a way of doing this using IAsyncResult, and eventhandling
but..no article really explained how to use it properly.
|
by: Ashwin Kambli |
last post by:
Hi,
I have a simple socket application. There is a server, and there are many
TCP connections to the server.
Now, if any one of those connections is lost, is there a way of triggering
an event on the server for this.
What I need is to set up a delegate to handle this disconnection (Delegate
has some cleanup code). As soon as the socket is disconnected, the event
should call the delegate.
Thanking you,
Ashwin Kambli
|
by: Vladimir Lushnikov |
last post by:
Hi,
I know there exist asynchronous socket methods for connecting,
receiving/sending data and disconnecting - but how do you know when the
socket has been terminated - can you assign an event handler or a
delegate as to when the socket is disconnected - either gracefully from
remote or shut down by "brute force"?
In short, something like this:
|
by: Techsol |
last post by:
Hi, I have synchronous communications between a server and client. To save bandwith the connection must persist. So the socket must stay open and only be re-opened in case of communications failure. To simulate failure, the server disconnects the socket. However, the client socket parameter shows an open socket: socket.connected is true, socket. Active is true, socket.poll(1,selectRead) is true. When checking the MS class documentation, it is...
|
by: Cheryl |
last post by:
Hi. I am having a problem on handling asynchronous sockets in C#. I
implemented a pair of client and server sockets. The connection is ok when
first connected. However, when I turned off the server socket, the client
is able to connect, but cannot send anything out. It seems that the
Socket.Connected is false but I received no disconnection event. Any idea
on how to solve the problem?
Thanks.
| |
by: terron |
last post by:
I'm trying to make something that once it is disconnected will automatically try to reconnect. I'll add some more features in later so it doesn't hammer the server but right now I just want to keep it simple and get that part working. The problem is that when I use sock.close I get an error message of
Bad File Descriptor
and if I either use shutdown or just go straight to reconnecting I get:
Transport endpoint is already connected
This...
|
by: davy zhang |
last post by:
Python3.0rc1 windowsxp
in the lib\asynchat.py
def handle_write (self):
self.initiate_send()
def push (self, data):
sabs = self.ac_out_buffer_size
if len(data) sabs:
|
by: ofer1 |
last post by:
I have user with 3 open session in disconnected state on the same server.
I have the sessionid for each remote session with 'qwinsta' command.
Is it possible to reconnect to specific session by using its sessionid
without getting the "Connect to existing Remote Desktop" message.
Like the opposite of the 'tsdiscon' command, 'tscon' doesn't get the 'server' switch?
|
by: Dreea |
last post by:
Hello everybody
I am working on a client application that connects to a C# server using the Socket class. I am trying to handle the case in which the server goes offline, and I would like the client to try to reconnect after the previous connect times out.
Currently I try to re-connect on the IOErrorEvent.IO_ERROR event handler. The issue is that it seems like the socket is not trying to make another connection.
I've seen the following...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |