473,395 Members | 1,668 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,395 software developers and data experts.

BeginReceive throws Request Timeout exception for the second call.

Hi All,
I have used the available code snippet from microsoft for socket
communication.
But the following code throws an error mentioned above. Please check the
code and help me asap.
private static void ReceiveCallback(IAsyncResult IResult)
{
try
{
// Retrieve the state object and the client socket from the
asynchronous state
//object.
StateObject objState = (StateObject) IResult.AsyncState;
Socket socClient = objState.msocSocket;

// Read data from the remote device.
int intBytesRead = socClient.EndReceive(IResult);

if(intBytesRead > 0)
{
// There might be more data, so store the data received so far.
objState.msbdDataReceived.Append(Encoding.ASCII.Ge tString
(objState.mbytBuffer, 0, intBytesRead));

// Get the rest of the data.
socClient.BeginReceive(objState.mbytBuffer, 0,
StateObject.BUFFER_SIZE, 0, new AsyncCallback(ReceiveCallback), objState);
}
else
{
// All the data has arrived; put it in response.
if (objState.msbdDataReceived.Length > 1)
{
mstrResponse = objState.msbdDataReceived.ToString();
}

// Signal that all bytes have been received.
mevtReceiveDone.Set();
}
}
catch(Exception objException)
{
throw objException;
}
}

The problem is that BeginReceive works as long as the Server return data
i.e. for example: Server return A 1st time, B 2nd time and if there is no
more data for the third time and if BeginReceive method is called, it throws
request timeout error.
Thanks in advance.
faktujaa
Jul 21 '05 #1
0 1577

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

Similar topics

3
by: TP-Software | last post by:
Hi, This code doesn't seem to work it always says "there is more data" and also this method is only called once private void AsyncReadCallBack(IAsyncResult asyncResult) {
2
by: dream machine | last post by:
Hi all , with BegeinReceive I can build async method of Socket Class that Receive the data from the Socket Client . My question is , if I have this code that create 3 Receive Async Call : ...
0
by: ?lafur Helgi R?gnvaldsson | last post by:
I'm building a server application which accepts socket connections and I ran into some problems. The socket is asynchronous and therefore uses the BeginXXX and EndXXX methods in the Socket class...
4
by: Anders Borum | last post by:
Hello! I am working on improving my threading skills and came across a question. When working with the ReaderWriterLock class, I am getting an unhandled exception if I acquire a WriterLock with...
6
by: Steve Richter | last post by:
I dont get the point of socket.BeginReceive and socket.EndReceive. As I understand it, BeginReceive will start a 2nd thread, call the ReceiveCallback delegate in the 2nd thread, then block until...
0
by: faktujaa | last post by:
Hi All, I have used the available code snippet from microsoft for socket communication. But the following code throws an error mentioned above. Please check the code and help me asap. private...
22
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to...
0
by: rcarmich | last post by:
I am having an issue canceling a beginReceive call on a timeout. For example, the following function: public int ReadBytes(Socket theSock, byte arr, int startByte, int length, int timeout) {...
0
by: darfur | last post by:
I'm writing an application that simplifies the interface to a few websites I use at my job. One of the web servers has a tendency to cause my program to throw a time out exception for a variety of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
Oralloy
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,...
0
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...
0
tracyyun
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...

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.