473,289 Members | 2,106 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,289 software developers and data experts.

Why does the message send only once?

Why does the message send only once?

The node sends once, then fails after that.

<code>
import socket
import thread
import time

def Node(nodeAddress):

'''connect to node and get its file load'''

sN = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
# Echo client program
HOST = nodeAddress # The remote host
PORT = 50007 # The same port as used by the server
sN = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
sN.connect((HOST, PORT))
sN.send('Hello, world')
data = sN.recv(1024)
sN.close()
print 'Received', repr(data)

def Server(address):

''' starts a socket server and decides what to do with incomming
stuff'''
message = "hello from server"
HOST = '' # Symbolic name meaning the local host
PORT = 50007 # Arbitrary non-privileged port
sP = None
sL = None
sR = None
sS = None
sStor = 0
sTotalStorage = 0
sCT = (sP,)
'''look in server.conf for connect_to_server value'''

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1)
conn, addr = s.accept()
print 'Connected by', addr
while 1:
print message
time.sleep(1)
data = conn.recv(1024)
#if not data: break
conn.send(data)
conn.close()

thread.start_new(Server,('',))
thread.start_new(Node,('127.0.0.1',))
while 1:
time.sleep(5)
thread.start_new(Node,('127.0.0.1',))
</code>

Oct 16 '07 #1
3 1713
danfolkes wrote:
Why does the message send only once?
Because your server is designed to only accept one connection, wait
forever except there is an exception, and quit thereafter.
def Server(address):
[...]
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((HOST, PORT))
s.listen(1) # ----- set up listening
conn, addr = s.accept() # ----- accept one connection
print 'Connected by', addr
while 1:
print message
time.sleep(1)
data = conn.recv(1024) # ----- receive stuff
#if not data: break
conn.send(data) # ----- send stuff
conn.close() # ----- close connection
# ----- quit
Personally, I like the Twisted framework more than low-level socket
interfaces. Consider giving it a try -- your code will be much
easier to read and maintain. You don't have to waste time
implementing the server or client basics but can fully concentrate
on your protocol(s).

Regards,
Björn

--
BOFH excuse #168:

le0: no carrier: transceiver cable problem?

Oct 16 '07 #2
On Tue, 16 Oct 2007 15:55:31 +0000, danfolkes wrote:
Why does the message send only once?

The node sends once, then fails after that.
Because the `Server` just seems to handle the first connection and is done
then. Insert some ``print``\s to see what's going on.

Ciao,
Marc 'BlackJack' Rintsch
Oct 16 '07 #3
danfolkes a écrit :

<OT>
You already posted the same question here one hour and a half ago.
Please avoid.
</OT>
Oct 16 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: jasonbrown1999 | last post by:
Someone told me the following script could be used to run harmful commands on the server, by passing commands into the script. What the script does is encode an affiliate URL, create two frames,...
2
by: Jagdip Singh Ajimal | last post by:
I have setup an email notifications system, that basically takes each row from a table and sents out an email according to the data in that row. The emails get sent, with the subject being filled...
2
by: Chris | last post by:
Im hoping someone can help me understand why this works? Requirement: Navigate DOM through javascript to perform DHTML actions. Issue: GIANT html document, up to 4MB in size, thousands and...
1
by: Kitchen Bin | last post by:
Hi. I am trying to use Sockets to do multiple Send and Receives via HTTP (not simultaneously). A first pair of Send/Receives works fine and sure enough I receive HTML back, but the next...
4
by: Winston Nimchan | last post by:
Hi: I'm currently developing a socket application and would like to precede the data being sent with a 4 byte message length header (bin4). Can anyone help Regards Winston
4
by: Chris Tanger | last post by:
Context: C# System.Net.Sockets Socket created with constructor prarmeters Internetwork, Stream and TCP everything else is left at the default parameters and options except linger may be changed...
89
by: Cuthbert | last post by:
After compiling the source code with gcc v.4.1.1, I got a warning message: "/tmp/ccixzSIL.o: In function 'main';ex.c: (.text+0x9a): warning: the 'gets' function is dangerous and should not be...
7
by: Guy Davidson | last post by:
Hi Folks, I'm having some issues with an small socket based server I'm writing, and I was hoping I could get some help. My code (attached below) us supposed to read an HTTP Post message...
2
chunk1978
by: chunk1978 | last post by:
i wrote a custom PHP script last year and everything worked perfectly... recently my webserver upgraded to PHP 5 and now my script doesn't work properly. what the script does is: users fill out...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.