Hello,
I'm having a problem with sending data with sockets over a dial-up
connection. When I use the send function, it will happily send a
buffer of a megabyte and more in one shot. But of course, the data is
still in the network buffer... Meaning you can't disconnect for awhile
(but for how long...). The problem is, how can I know when it's done?
Is there a way to be notified when the data has truly been sent?
I tried using setsockopt and SO_SNDBUF to reduce the send buffer size,
thinking that the data would actually send in smaller increments,
instead of putting the whole thing in a buffer and taking it out of my
hands... No luck. It all works, mind you, but I'm left clueless as to
when the data is really off my computer!
I'm just following the example in the Python sockets How-To. Here's
the send function:
def mysend(msg):
totalsent = 0
while totalsent < MSGLEN:
sent = self.sock.send( msg[totalsent:])
if sent == 0:
raise RuntimeError, \\
"socket connection broken"
totalsent = totalsent + sent
Is there something I'm missing, or is there a better way to do this?
Thanks,
-Marc
Jul 18 '05
12 2308 me*****@hotmail .com (Marc Ederis) wrote in message news:<f0******* *************** ****@posting.go ogle.com>... I'm having a problem with sending data with sockets over a dial-up connection. When I use the send function, it will happily send a buffer of a megabyte and more in one shot. But of course, the data is still in the network buffer... Meaning you can't disconnect for awhile (but for how long...). The problem is, how can I know when it's done? Is there a way to be notified when the data has truly been sent?
You can get pretty close if you are willing to close the socket (but
since you want to disconnect, that should be fine).
What you need to do is turn on linger mode with a very large timeout (large
enough so that your slow connection has enough time to send the data).
Once linger is turned on, close() will block until all the data has
been sent.
The one issue that you can run into is if the linger time runs out before
all the data is sent then the rest of the data is discarded. But as long
as you set linger long enough (how about 10 years), you will run out of
patience long before the data is discarded.
samuel
Richie Hindle <ri****@entrian .com> wrote in message news:<ma******* *************** *************** *@python.org>.. . If you want to ensure that all the data has been sent before *closing* the socket, which sounds like Marc's requirement, you can use setsockopt(SO_L INGER):
SO_LINGER Sets or gets the SO_LINGER option. The argument is a linger structure.
struct linger { int l_onoff; /* linger active */ int l_linger; /* how many seconds to linger for */ };
When enabled, a close(2) or shutdown(2) will not return until all queued messages for the socket have been successfully sent or the linger timeout has been reached. Otherwise, the call returns imme* diately and the closing is done in the background. When the socket is closed as part of exit(2), it always lingers in the background.
(from the GNU manpages). I don't believe that's true for shutdown() on all platforms, but I do believe it's true for close() / closesocket(). Calling it from Python is a bit of a chore involving the struct module, and is left as an exercise for the reader. 8-)
SO_LINGER... Interesting, I'll keep that in mind for the future. In
the end, acknowledging receipt of the data, as it was arriving at the
server, turned out to be the best solution for me. I wanted to be able
to show a progress bar (at the client) of the data being sent.
Thanks guys,
-Marc
Sion Arrowsmith <si***@chiark.g reenend.org.uk> wrote: The way to tell that data has been sent is to use an application-level protocol that acknowleges the data transferr.
applies in spades if you care about reliability.
Oh yep: http://web.mit.edu/Saltzer/www/publi...d/endtoend.pdf
Alex This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Robert A. van Ginkel |
last post by:
In news:OZ0W9RsdDHA.2432@TK2MSFTNGP10.phx.gbl... I ask the question how I
can see if all the data is on the other side of the connection.
I got as answer that I should use the blocking property.
I tried this I don't see any diffents, I am sending 10Mb and the
Send/BeginSend command doesn't wait till the data is on the remotepoint.
Can somebody pls. explain this.
Regards Robert.
|
by: Laxmikant Rashinkar |
last post by:
Is there any way to use a C# socket in promiscuous mode?
Any sample code that shows how this is done?
any assistance is much appreciated!
thanks
LK
|
by: Stuart Norris |
last post by:
Dear Group,
I am having a problem setting SocketOptionName.SendTimeout on a client
TCPIP application using the sockets in .NET. From the on-line help it
is possible to set a SocketOptionName.SendTimeout for sends on TCPIP
sockets.
In all the tests that I have done with both Async and Sync sends the
send returns immediately with the number of bytes sent (< 100 in my
messages).
|
by: Michael Maercker |
last post by:
hi!
i'm really not into networking at all and have now been asigned the task of
porting a vb6-code into vb.net (compact framework, in this case) and the
code uses the winsock-control. i quickly found out that .net uses
system.net.sockets.socket or .tcpclient/.tcpserver. and these confuse me...
:o| and help would be really great! links, code, wrappers, tips,
whateveryougot...
one of my main problems, i guess, is: why don't sockets...
|
by: a_agaga |
last post by:
Do you know are there some reasons why many do not make processes to
communicate through memory?
Why network connections (sockets) are used so commonly in IPC (inter
process communication) instead of memory?
(Is IPC harder to maintain / handle if it is made through memory, when
compared to communication through sockets?)
Some background things:
| |
by: eliss.carmine |
last post by:
I'm using TCP/IP to send a Bitmap object over Sockets. This is my first
time using C# at all so I don't know if this is the "right" way to do
it. I've already found out several times the way I was doing something
was really inefficient and could reduce 10 lines of code with 2, etc.
For reading, I am using a TcpClient and I call
NetworkStream ns = client.GetStream(); to get a stream
stream.Read(buffer, 0, buffer.Length);
|
by: Cichy |
last post by:
Hello,
I'm writing a Client-Server application using sockets (asynchronous).
There is a Server (Master) which accepts incoming connections, and
Client (Slave).
Afetr establishing connections with all Slaves I wanna hit a button
"Automatic", then everything must be reorganised, there is an
ellection for a new Master.
Everything is all right when I'm connecting manually (when I hit a
button connect), but after hitting this button...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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: 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: 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: 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...
| |