473,473 Members | 1,805 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

About BeginReceive method

18 New Member
hi

the following code written for receive data continuously from other end;
i used tcplistener for listening and tcpclient for client socket.

public void WaitandReceiveData()
{
try
{

data = new Byte[TC.Client.ReceiveBufferSize];
TC.Client.BeginReceive(data, 0, data.Length, SocketFlags.None, new AsyncCallback(AfterDataReceived), TC.Client);
}
catch (Exception excp)
{
ErrorLog.WriteError("Wait And Receive Data", excp.Message);
}

}
private void AfterDataReceived(IAsyncResult result)
{
try
{
//i used received data
TC.Client = (Socket)result.AsyncState;
WaitandReceiveData();
}
catch (Exception excp)
{
ErrorLog.WriteError("After Data Received", excp.Message);
}
}


but this code will not works for all time and it also does not notifies the data arrival.

i also tried out with blocking mode of tcpclient.

the callback is called immediately.

how to make this code to receive continuouly and wait for data arrival?
help me please...
thanks in advance
May 7 '08 #1
0 776

Sign in to post your reply or Sign up for a free account.

Similar topics

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...
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 : ...
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...
3
by: Josema | last post by:
Hi, Im starting working with sockets. im making a server and a client (tipical starter) application. About the BeginReceive Method, i dont understand why if i execute the line one time, i...
4
by: Ryan Liu | last post by:
TcpClient has a method called GetworkStream GetStream(); So in other words, there is only one stream associate with it for input and output, right? So while it is receiving, it can not send, and...
5
by: Jason Richmeier | last post by:
I have been unable to locate an answer for this question because (1) it is late in the day and my eyes are tired of looking at code and documentation, (2) I am new to this area of the .NET...
0
by: tccode97 | last post by:
To whom it may concern, I am developing a socket application in VC++ that uses asynchronous connnection. After doing search on google, I found the following link ...
2
by: Marcel Brekelmans | last post by:
Hi, I use a socket to receive data from a certain process. I use the asynchronous operations BeginReceive() and EndReceive(), with a callback in BeginReceive. Now all documentation says that the...
9
by: semedao | last post by:
Hi, I am using sync and async operations on the same socket. generally I want the socket to wait on BeginReceive and to not block the object thread. but in some cases I want to stop the...
2
by: O.B. | last post by:
In the following code snippet, the thread successfully makes it to the line where it waits for data to be received. Then the client closes the connection. The thread wakes up and returns from the...
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,...
1
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...
0
agi2029
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,...
1
isladogs
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...
0
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.