Click here to Skip to main content
15,897,891 members
Home / Discussions / C#
   

C#

 
AnswerRe: Renaming Pin
Ghydo5-Nov-09 5:57
Ghydo5-Nov-09 5:57 
AnswerRe: Renaming Pin
Richard MacCutchan5-Nov-09 6:00
mveRichard MacCutchan5-Nov-09 6:00 
QuestionMulti level pie chart? Pin
BetimD5-Nov-09 5:18
BetimD5-Nov-09 5:18 
AnswerRe: Multi level pie chart? Pin
Saksida Bojan5-Nov-09 6:32
Saksida Bojan5-Nov-09 6:32 
QuestionStrange Property Grid Behaviour Pin
Wags5-Nov-09 4:37
professionalWags5-Nov-09 4:37 
AnswerRe: Strange Property Grid Behaviour Pin
Saksida Bojan5-Nov-09 7:00
Saksida Bojan5-Nov-09 7:00 
AnswerRe: Strange Property Grid Behaviour Pin
Wags5-Nov-09 23:20
professionalWags5-Nov-09 23:20 
Questionproper Async reading operation Pin
Chesnokov Yuriy5-Nov-09 4:25
professionalChesnokov Yuriy5-Nov-09 4:25 
I've got a class which connects to server. Then the server sends to client at some specific time intervals data.

I've got a problem in recieving that data if single read is less than the whole data to be transfered

e.g. 10K is going to be sent. I BeginRead with 1024 buffer as in TcpClientData class with all public fields.

These are the 2 functions from the class

class MyClient
{

private void ConnectButtonClick(object sender, EventArgs e)
{
TcpClient tcpClient = new TcpClient();                                
tcpClient.Connect(ipAddress, port);
NetworkStream ns = tcpClient.GetStream();
//TcpClientData is a class with all public fields
TcpClientData cd = new TcpClientData();
cd.tcpClient = tcpClient;
cd.ms = new MemoryStream;
cd.packet = new byte[1024];
ns.BeginRead(cd.packet, 0, cd.packet.Length, new AsyncCallback(TcpClientDataReadAsyncCallback), cd);
}

private void TcpClientDataReadAsyncCallback(IAsyncResult ar)
{
TcpClientData cd = (TcpClientData)ar.AsyncState;
NetworkStream ns = cd.tcpClient.GetStream();
int sz = cd.ns.EndRead(ar);
                        
cd.ms.Write(cd.packet, 0, sz);
while (ns.DataAvailable == true)
        ns.BeginRead(cd.packet, 0, cd.packet.Length, new AsyncCallback(TcpClientDataReadAsyncCallback), cd);

//supposed that the whole data recieved
//show cd.ms.Length
//cd.ms.Length always 1024 bytes
//fails to loop in while??

//
//process that whole data from MemoryStream cd.ms
//

//keep waiting for more data on the next server data sent        
cd.ms.SetLength(0);
cd.ns.BeginRead(cd.packet, 0, cd.packet.Length, new AsyncCallback(TcpClientDataReadAsyncCallback), cd);
}

}


What is wrong?

Чесноков

AnswerRe: proper Async reading operation Pin
Jimmanuel5-Nov-09 5:55
Jimmanuel5-Nov-09 5:55 
GeneralRe: proper Async reading operation Pin
Chesnokov Yuriy5-Nov-09 8:28
professionalChesnokov Yuriy5-Nov-09 8:28 
QuestionAssembly redirection in .NET Pin
KarthikonIT5-Nov-09 4:18
KarthikonIT5-Nov-09 4:18 
AnswerRe: Assembly redirection in .NET Pin
Not Active5-Nov-09 5:43
mentorNot Active5-Nov-09 5:43 
QuestionTransparency Pin
stancrm5-Nov-09 3:43
stancrm5-Nov-09 3:43 
AnswerRe: Transparency Pin
The Man from U.N.C.L.E.5-Nov-09 7:38
The Man from U.N.C.L.E.5-Nov-09 7:38 
QuestionHelping -- winpcap & winDump libraries for capture and dump IP packets using C# Pin
3bood.ghzawi5-Nov-09 2:21
3bood.ghzawi5-Nov-09 2:21 
Questionsizeof struct with array Pin
Ronenb5-Nov-09 2:03
Ronenb5-Nov-09 2:03 
AnswerRe: sizeof struct with array Pin
Luc Pattyn5-Nov-09 2:23
sitebuilderLuc Pattyn5-Nov-09 2:23 
GeneralRe: sizeof struct with array Pin
Ronenb7-Nov-09 19:16
Ronenb7-Nov-09 19:16 
GeneralRe: sizeof struct with array Pin
Luc Pattyn8-Nov-09 1:07
sitebuilderLuc Pattyn8-Nov-09 1:07 
GeneralRe: sizeof struct with array Pin
Ronenb8-Nov-09 4:36
Ronenb8-Nov-09 4:36 
QuestionSplit Name Field Pin
kruegersck5-Nov-09 1:58
kruegersck5-Nov-09 1:58 
AnswerRe: Split Name Field Pin
musefan5-Nov-09 2:30
musefan5-Nov-09 2:30 
AnswerRe: Split Name Field Pin
Shameel5-Nov-09 2:33
professionalShameel5-Nov-09 2:33 
AnswerRe: Split Name Field Pin
V.5-Nov-09 4:21
professionalV.5-Nov-09 4:21 
AnswerRe: Split Name Field Pin
PIEBALDconsult5-Nov-09 5:34
mvePIEBALDconsult5-Nov-09 5:34 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.