Geeks With Blogs

News

qrcode

Lance Robinson

Create Your Badge

Lance Robinson is a software engineer in Durham, Chapel Hill, Raleigh, and surrounding areas. More about Lance.

 Subscribe


Lance's TextBox » About Me » My Resume »Twitter
Winsock error 10035 means "Resource not available" or "Operation would block". Huh?

This error happens when the winsock buffer of either the client or server side become full. Huh? Ok, let me try to describe it as plainly as possible:

Here are two situations in which you might see Winsock error 10035:

  • You're trying to send a massive amount of information through the socket, so the output buffer of the system becomes full.
  • You're trying to send data through the socket to the remotehost, but the remotehost input buffer is full (because its receiving data slower than you're sending it).

When you send data - you really send it to the TCP/IP subsystem of your machine (ie winsock). The system buffers this data (in the OutBuffer) and begins sending it to the remote host as fast as it can (which of course is only as fast as the receiver can receive it). If the OutBuffer gets filled, because you are sending data faster than the system can send it - you'll get Winsock error 10035.

For IP*Works! users, you will never have to worry about this error because the components deal with them for you automatically, with the exception of IPPort an IPDaemon, the basic level TCP client and server components. These two components are the building blocks with which you can build any TCP/IP solution, they give you complete control over everything.

In order to deal with this when using IPPort or IPDaemon, just catch the Winsock 10035 error and wait for the component's ReadyToSend event to fire (this fires when the system is able to send data again). At that time, you can continue sending your data, starting with that which failed. For example (C# - if you need help with other languages let me know), the code below will loop until the length of the data to be sent is 0. If all goes normally, this loop will only be entered once and all of the data will be sent. After a while, if the input buffer fills up, the SetDataToSend inside the loop will fail with the Winsock 10035 error. The code will wait for the ReadyToSend event (the ready boolean flag), and loop. SetDataToSend will be called again, successfully.

note:  The ReadyToSend event will only fire if none of the data was able to be sent.  So the code below has been updated to only wait for the event if BytesSent equals 0.  Otherwise, if some of the data was able to be sent, the code will loop immediately and attempt to resend the remaining data.

while (length > 0) { //this means that we have some bytes to send
     try 
     {
          ready = false;
          ipport1.SetDataToSend(TextB, offset, length);
          length -= ipport1.BytesSent;
          tbStatus.AppendText(ipport1.BytesSent.ToString() + " bytes sent." + "\r\n");
     }
     catch (nsoftware.IPWorks.IPWorksException ex1) 
     {
          if (ex1.Code == 135) //WOULDBLOCK Error
          {
               if (ipport1.BytesSent == 0) 
while (!ready) { ipport1.DoEvents(); }
               length -= ipport1.BytesSent; offset += ipport1.BytesSent;
               tbStatus.AppendText("Retrying Send..." + "\r\n"); 
          }
     }
}

Posted on Wednesday, July 20, 2005 8:52 AM Programming | Back to top


Comments on this post: Winsock error 10035

# re: Winsock error 10035
Requesting Gravatar...
So if you got this error can we proceed with our work by sending the data ?when the input buffer or output bufer will get empty.
Left by Madhavi on May 25, 2006 12:12 AM

# re: Winsock error 10035
Requesting Gravatar...
The buffer doesn't have to be empty before you can send data - it just can't be full. The system will let you know when: in the case of IP*Works!, the component will notify you by firing its ReadyToSend event. At that point you resend however many bytes didn't make it through (which will likely be all the bytes that you most recently tried to send).
Left by Lance Robinson on May 25, 2006 6:26 AM

# re: Winsock error 10035
Requesting Gravatar...
What about this error during recv?
Left by mtourangeau on Jan 17, 2007 12:39 PM

# re: Winsock error 10035
Requesting Gravatar...
You have a solution for VB6

Thanks

Jörg
Left by Jörg Schultz on Jul 31, 2007 6:34 AM

# re: Winsock error 10035
Requesting Gravatar...
The solution for vb6 is the same. Just convert the code.
Left by Lance on Aug 01, 2007 10:37 AM

# re: Winsock error 10035
Requesting Gravatar...
I have the same error when i RECEIVE data from server, on client side. I using Socket.Blocking = false. Receive buffer is big enough, I don't think that is the issue.

Server - Linux, c++
Client - Windows, C#

Thanks in advance,
Evgeni
Left by Evgeni on Nov 05, 2007 10:36 AM

# re: Winsock error 10035
Requesting Gravatar...
If you are using a non-blocking socket for RX and call recv(...) and no data is available, you will get this error because the call would have to block while waiting on data - so in the RX case ignore the error.
Left by Bob on Jan 30, 2008 4:10 PM

# re: Winsock error 10035
Requesting Gravatar...
Can you tell how to overcome this problem using SENDMAIL.

Left by abcdefgh on Mar 25, 2008 1:07 AM

# re: Winsock error 10035
Requesting Gravatar...
Hi Lance,

I copied your code above (converted to Delphi) and I get an endless loop because ipport1.BytesSent = 0 after the SetDataToSend. Is there any property I need to set for ipport to get the correct BytesSent? If I simple call SetDataToSend without any checking or loop I also get 0 BytesSent even though the data was sent correctly. Why is that?

Thank you.
Left by TN on May 15, 2008 2:49 PM

# re: Winsock error 10035
Requesting Gravatar...
TN - I cannot reproduce this here. What version are you using? Can you email me your sample code?
Left by Lance on May 15, 2008 2:55 PM

# re: Winsock error 10035
Requesting Gravatar...
Lance,

Thanks for the quick reply. I'm using IPWork SSL Delphi Edition version 5.0 (Build 1182) with Delphi 7. The code can be as simple as this:

procedure SendToClient(ID: integer; S: String);
var
i: integer;
begin
ipServer.DataToSend[ID] := S;
i := ipServer.BytesSent[ID];
end;

In the above example i always returns 0 even though it sent the data fine. This happens both with the IPPortS or IPDaemonS components.

Thanks.
Left by TN on May 15, 2008 5:07 PM

# re: Winsock error 10035
Requesting Gravatar...
When does ready get set to true in the above example. I tried putting it in the IpPort ReadyToSend event but it never goes in there after an operation would block. It simply loops through DoEvents infinitely.

Any help would be appreciated.

Thanks.
Left by Michael on Sep 29, 2008 9:38 AM

# re: Winsock error 10035
Requesting Gravatar...
Yes, ready gets set to true inside IPPorts ReadyToSend event. If the ReadyToSend event is not firing for you, make sure that the receiving end is processing incoming data, and if that is not the problem, I recommend you contact /n software support and let them know what version/build you have.
Left by Lance on Sep 29, 2008 9:47 AM

# re: Winsock error 10035
Requesting Gravatar...
I'm both the sending and receiving end so I'm pretty sure my daemon is receiving data. I'm using version 8.0.3022.0 so I guess I'll contact live support. Thanks for your help.
Left by Michael on Sep 29, 2008 11:22 AM

# re: Winsock error 10035
Requesting Gravatar...
We send a massive amount of information through the socket using the SendLine method of IPDaemon component. Now, our problem is: when we send the information using this method, some bytes of the information are sent and the winsock buffer of either the client or server side becomes full, remaining bytes are then sent in catch body of the code when the ready variable is set to true.
We think this can cause problems for the client side application.

What we want is not to send an information message if the buffer does not have enough capacity to hold it completely, and wait until an appropriate time. We want to send the message completely, or wait until it can be sent. Is there a way to calculate the approximate remaining buffer (client or server side) size?
Any help would be appreciated,

Thanks,

Left by Sen on Nov 03, 2008 9:53 AM

# re: Winsock error 10035
Requesting Gravatar...
Sen - use email for anymore followup.
The component cannot give you this, but even if it could, it would be the result of attempting to send to the client.
Left by Lance on Nov 03, 2008 11:54 AM

# re: Winsock error 10035
Requesting Gravatar...
Dear Lance,
Thank you for the quick reply.
I've another question. What is the main functionality of DoEvents method?
Left by Sen on Nov 04, 2008 3:27 AM

# re: Winsock error 10035
Requesting Gravatar...
Hi,

I have a question regarding ipport. What is the equivalent method of ipport.InBufferSize in ipport in .NET?

I'm not sure of the version. The InBufferSize method was present in ipport when i was using embedded Visual Basic. We're migrating to .NET but the old method is not there.

Thanks,
Bernard
Left by Bernard on Nov 21, 2008 3:38 AM

# re: Winsock error 10035
Requesting Gravatar...
Bernard: ipport1.Config("InBufferSize=64000")
Left by Lance on Nov 21, 2008 9:19 AM

# re: Winsock error 10035
Requesting Gravatar...
Dear Lance,
We use your solution in our multithreaded application. We have 3 threads that send data using the method above.
How can I synchronize the usage of method. The application gets locked after a time.
Any help will be appreciated...
Thanks,
Sen
Left by sen on Jan 23, 2009 7:43 AM

# re: Winsock error 10035
Requesting Gravatar...
We use IPDaemon component in our application. When the ipDaemon component buffer is filled (winsock error 10035 occurs) the application enters into catch block.

We recognised that the OnReadyToSend event is never called, unless a client connects to the application. And the application gets locked.

Could you please advise about the problem?

Method body:

readyToSend = true;

private void SendTradeMessage(string connectionId, string lastTradeValue)
{
try
{
ipdaemon1.SendLine(connectionId, lastTradeValue);
}
catch(nsoftware.IPWorks.IPWorksException ex)
{
if (ex.Code == 135)
{
readyToSend = false;

while (!readyToSend)
{
ipdaemon1.DoEvents();
}
SendTradeMessage(connectionId, lastTradeValue);
}
}
}

private void ipdaemon1_OnReadyToSend(object sender, IpdaemonReadyToSendEventArgs e)
{
readyToSend = true;
}
Left by sen on Jan 23, 2009 9:20 AM

# re: Winsock error 10035
Requesting Gravatar...
Sen, so the ReadToSendy event is not firing for you? What are you sending to? Is it reading its incoming data? I will email you so we can have this conversation in a more convenient place.
Left by Lance on Jan 23, 2009 9:26 AM

# re: Winsock error 10035
Requesting Gravatar...
It sounds like you may have an old build...if you get the latest from our website (free update), it will work as expected.
Left by Lance on Jan 27, 2009 12:10 PM

# re: Winsock error 10035
Requesting Gravatar...
Dear Lance,

We installed the new version. our version was an older one.

When is OnReadyToSendEvent fired? We need sth. that fires when the server buffer is available.

Today we saw that at a busy hour of the day (when lots of data is sent via ipdaemon) our application was locked.
We didn't get any error log, so we do not really know the reason. We suspect that the buffer gets full and somehow the application enters into an endless loop. Also we are not sure if the onReadyToSend event fires when the buffer is full.

Our application is a multi-threaded application. Each thread sends data via the same IPDaemon component as our application receives data from another server. SendMessageToAllConnections method is called from each of the three threads as data to send comes.
We used “lock” statement to prevent other threads from using the ipdaemon1 instance. Can it also be the cause of the problem?

The codes are shown below.

internal void SendMessageToAllConnections(string message)
{
try
{
foreach (Connection connection in ipdaemon1.Connections.Values)
{
if (connection.Connected)
{
SendMessage(connection.ConnectionId, message);
}
}
}
catch (Exception ex)
{
if (log.IsErrorEnabled) log.Error(ex.Message, ex);
}
}

internal void SendMessage(string connectionId, string message)
{
try
{
lock (ipdaemon1)
{
ipdaemon1.SendLine(connectionId, IPDaemonMessageField.STX + message + IPDaemonMessageField.ETX);
}
}
catch (nsoftware.IPWorks.IPWorksException ex)
{
readyToSend = false;
if (ex.Code == 135)
{
while (!readyToSend)
{
ipdaemon1.DoEvents();
}
SendMessage(connectionId, message);
}
}
}

private void ipdaemon1_OnReadyToSend(object sender, IpdaemonReadyToSendEventArgs e)
{
readyToSend = true;
}

Thanks,
Left by sen on Jan 30, 2009 9:58 AM

# re: Winsock error 10035
Requesting Gravatar...
Lance...

Thanks a ton mate...

Left by Vinod Basi (India) on Dec 06, 2011 6:11 AM

Your comment:
 (will show your gravatar)


Copyright © Lance Robinson | Powered by: GeeksWithBlogs.net