Hello,
I am beginner but so I need help. I have small script for receive data
from port 3883, but it print only once.
import socket
HOST = 'localhost'
PORT = 3883
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
s.connect((HOST , PORT))
data = s.recv(2048)
s.close()
print 'receive data from server:', `data`
So I try to write cycle to this script, like this:
import socket
HOST = 'localhost'
PORT = 3883
s = socket.socket(s ocket.AF_INET, socket.SOCK_STR EAM)
while 1:
s.connect((HOST , PORT))
data = s.recv(2048)
s.close()
print 'receive data from server:', `data`
But Python reporting:
Traceback (most recent call last):
File "C:\Documen ts and Settings\poupa\ Plocha\TCP3.py" , line 7, in
<module>
s.connect((HOST , PORT))
File "<string>", line 1, in connect
File "C:\Python25\li b\socket.py", line 141, in _dummy
raise error(EBADF, 'Bad file descriptor')
error: (9, 'Bad file descriptor')
Where is the mistake? I dont know.
thaks for help
Petr 0 1102 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bryan Olson |
last post by:
Here's the problem: Suppose we use:
import socket
f = some_socket.makefile()
Then:
f.read() is efficient, but verbose, and incorrect (or at
least does not play will with others);
|
by: drs |
last post by:
Hi,
I have a program which opens a socket server in a thread. I need for the
server to listen on the socket for a certain amount of time (say, ten
seconds or so) and then close it, and am wondering if there is a good way to
close the socket other than sending it a message from another thread to
close itself. That is, I am looking for a way to forcably kill a socket
from a second thread, not to send it a message to kill itself.
...
|
by: Bernhard Schmidt |
last post by:
Hello,
sorry for bothering, I'm not a programmer and I don't do much python,
I'm more a networking guy trying to get his favourite linux distribution
to update through the shiny new protocol IPv6 again (for those who are
interested, I'm talking about Gentoo Linux)
Gentoo's portage system is implemented in python calling rsync to sync
with a mirror server. There are rotations (metahostnames with many
address records) where portage has...
|
by: Tom Opgenorth |
last post by:
I'm experiencing a problem with sockets, and I'm really hoping someone can
help me, please and thank you.
I've written a TCP Server, which listens on a port for an incoming
connection. When the client connects, the connection is NEVER to be closed
by the server. The client will send messages as necessary. After each
message the server is to send an acknowledgement back to the client. That is
the client's indicator to send the next...
|
by: Abubakar |
last post by:
Hi,
lets say I have a connected SOCKET s. At some point in time, I want to know
if the "s" is still valid, that it is still connected. Is there any API that
I can give me this information?
And can I register some callback like thing, that would inform me when "s"
disconnection happens? What I usually do is while I call "send" or "recv", I
get the socket_error and through that I know whats the status. But in this
situation actually I...
| |
by: nephish |
last post by:
hey there,
i have a script that waits for message packets from a data server over
a socket.
it goes a little like this:
while 1:
x+=1
databack = sockobj.recv(158)
if databack:
|
by: atlaste |
last post by:
Hi,
In an attempt to create a full-blown webcrawler I've found myself
writing a wrapper around the Socket class in an attempt to make it
completely async, supporting timeouts and some scheduling mechanisms.
I use a non-blocking approach for this, using the call to 'poll' to
support the async mechanism - rather than the 'begin' and 'end'
functions. I already found that connecting doesn't set the
"isconnected" variable correctly...
|
by: O.B. |
last post by:
I have a socket configured as TCP and running as a listener. When I
close socket, it doesn't always free up the port immediately. Even
when no connections have been made to it. So when I open the socket
again, the bind fails because the port is still in use. When I
execute the code in "debug" mode, the problem never occurs. When I
execute the same code in release mode, the problem appears about 20%
of the time.
Here's the code:
|
by: Jean-Paul Calderone |
last post by:
On Mon, 12 May 2008 08:34:07 -0700 (PDT), petr.poupa@gmail.com wrote:
You cannot reconnect a socket. You need to create a new one for each
connection. It's also almost certainly the case that the way you are
receiving data is incorrect. There is no guarantee that you will get
2048 bytes from socket.recv(2048). It isn't even guaranteed that all
the bytes written to the socket by the peer will be returned by such
a call. Instead, you...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
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: 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...
| |