I am new to python, and I am trying to send a message over a TCP socket to another component (client). I have to send the message in chunks of 1024 bytes in response to client REQ.
The problem is that when first chunk of 1024 bytes is received by the client, it contains a character string appended at the end from the Initial Message that the client had sent as REQ.
What can I do to flush the socket connection before delivering the messsage
my setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR,1)
Thanks
Amit
1 37150
I'm not really sure what your problem is here, because I have never had it. If you post code, that would be most helpful. Anyway, for sockets, I would do something like this: - import socket
-
-
BUFF_SIZE=1024
-
REQUEST_SIZE=1024
-
-
class my_sock(socket.socket):
-
def __init__(self,*args,**kwds):
-
self.buffer=""
-
socket.socket.__init__(self,*args,**kwds)
-
def send(self,data):
-
self.buffer+=data
-
while BUFF_SIZE<len(self.buffer): # I am biased against > symbols
-
socket.socket.send(self,self.buffer[:BUFF_SIZE])
-
self.buffer=self.buffer[BUFF_SIZE:]
-
def flush(self):
-
self.buffer+=(BUFFER_SIZE-len(self.buffer)%BUFFER_SIZE)*"\x00"
-
self.send("")
-
-
sock=my_sock()
-
sock.bind(("",80)) # (address, port)
-
sock.listen(1)
-
while True:
-
s=sock.accept()
-
try:
-
data=s.recv(REQUEST_SIZE)
-
if data.startswith("This is an evil request for spam and eggs."):
-
s.send("No, it isn't. Spam isn't on the menu. Unless, of course, you get it with spam, spam, spam, spam, spam, spam, baked beans, spam, spam, spam, and spam.")
-
s.flush()
-
finally: # just in case something goes wrong, don't leave the socket open
-
s.close()
-
I haven't tested it, so I can't guarantee that it works, but that should be a start.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: John Abel |
last post by:
I'm hoping this is something simple, and someone can point me in the
right direction here. I have a class based on SocketServer
(ThreadingTCPServer), and I've used makefile on the socket so I use...
|
by: Manfred |
last post by:
Hello,
I am working on an interactive server/client setup, not using
INET::Sockets. Everything is gravy except for a little leftover stuff
being shown. I type a command w/ args, CLIENT join()s the...
|
by: Stephan Steiner |
last post by:
Hi
I have a networking application that periodically needs to go into sleep
mode (from an application point of view, I'm simply suspending the receiver
thread until it's time to start listening...
|
by: O.J. Tibi |
last post by:
Hi all,
I suspect I'm having problems with socket functions within my PHP
application running on Red Hat 2.4.21-4.EL #1/PHP 4.3.2/Apache 2.0.46.
Below is a sample code listing:
...
|
by: dansolo |
last post by:
Hi to all,
I would like to flush the datas in a tcp socket connection, however in the package socket I haven't found any function to do this work. I was thinking of opening and closing the socket...
| |
by: Chris |
last post by:
Hi,
I am using PHP persistent sockets and have a problem with them. The
problem is that PHP only sends the data when the socket is closed. In
the code example below the counterparty process...
|
by: madsornomads |
last post by:
Hi all,
I have a problem with reading from a Java server after I have written
to it - it just hangs. It works fine if I just write to the server and
not try to write. I have read the HOWTO on...
|
by: zbrozlo |
last post by:
Hi, I have strange problem with my perl program. My program consists of two parts, first written in python and second in perl. Perl part is a server, but also uses two sockets for "talking" with gui...
|
by: The Doctor |
last post by:
Hey people,
I have two applications:
the server, which creates a server socket, waits for a real-time signal,
and if it receives one, it creates a client socket.
The client, which will...
|
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,...
|
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,...
| |
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |