Click here to Skip to main content
15,889,901 members
Home / Discussions / C#
   

C#

 
AnswerRe: Min (110) must be less than or equal to max (-1) in a Range object. Pin
michal.drozdowicz23-Mar-09 5:03
michal.drozdowicz23-Mar-09 5:03 
QuestionCompare two .DAT file using C# Pin
Member 322226419-Feb-09 1:52
Member 322226419-Feb-09 1:52 
AnswerRe: Compare two .DAT file using C# Pin
Luc Pattyn19-Feb-09 2:20
sitebuilderLuc Pattyn19-Feb-09 2:20 
Questioncreating a setup file Pin
aratireddy19-Feb-09 1:26
aratireddy19-Feb-09 1:26 
AnswerRe: creating a setup file Pin
Ramkithepower19-Feb-09 1:38
Ramkithepower19-Feb-09 1:38 
GeneralRe: creating a setup file Pin
Calin Tatar19-Feb-09 1:52
Calin Tatar19-Feb-09 1:52 
AnswerRe: creating a setup file Pin
Nuri Ismail19-Feb-09 2:20
Nuri Ismail19-Feb-09 2:20 
QuestionReading specific no if bytes from an UDP datagram [modified] Pin
M. J. Jaya Chitra19-Feb-09 0:51
M. J. Jaya Chitra19-Feb-09 0:51 
Dear All,

I have an application which is reading a datagram from the client.

If the bytes to be read is greater that are equal to the byte sent, then it is working fine.

But my requirement is to read the data by 10 bytes at a time or specific bytes configured by the user.

I don't know how to achieve this.

The code used is:
private void OnReceive(IAsyncResult ar)
{
    try
    {
        IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
        EndPoint epSender = (EndPoint)ipeSender;

        int aCount = serverSocket.EndReceive(ar); // serverSocket.EndReceiveFrom(ar, ref epSender);

        Data msgReceived = new Data(byteData);

        string aReadData = System.Text.ASCIIEncoding.ASCII.GetString(byteData, 0, aCount);

        int aPacketEnd = aReadData.LastIndexOf("|");

        if (aPacketEnd == -1)
        {
            aPacketEnd = aReadData.LastIndexOf('\0');
        }
        if (aPacketEnd != -1)
        {
            string aValidData = System.String.Empty;
            string aPacketData = System.String.Empty;

    // Process the data
            if (myBuffer.Length > 0)
            {
                aValidData = System.Text.ASCIIEncoding.ASCII.GetString(myBuffer);
            }

            if (aPacketEnd < aCount - 1)
            {
                myBuffer = new byte[aCount - (aPacketEnd + 1)];
                System.Buffer.BlockCopy(byteData, aPacketEnd + 1, myBuffer, 0, aCount - (aPacketEnd + 1));
            }
            else
            {
                myBuffer = new byte[0];
            }

            System.Threading.Thread.Sleep(100);
            byte[] message =  new byte[10];
    // Frame the Acknowledgement data
            serverSocket.BeginSendTo(message, 0, message.Length, SocketFlags.None, epSender,
                new AsyncCallback(OnSend), epSender);
            byte []byteData = new byte[10];
            serverSocket.BeginReceiveFrom(byteData , 0, byteData.Length, SocketFlags.None, ref epSender,
                new AsyncCallback(OnReceive), epSender);
        }
        else
        {
            byte[] aTempArray = new byte[myBuffer.Length];
            System.Buffer.BlockCopy(myBuffer, 0, aTempArray, 0, myBuffer.Length);
            myBuffer = new byte[aTempArray.Length + (aCount)];
            System.Buffer.BlockCopy(aTempArray, 0, myBuffer, 0, aTempArray.Length);
            System.Buffer.BlockCopy(byteData, 0, myBuffer, aTempArray.Length, aCount);
            byteData = new byte[0];

            byteData = new byte[10];
            serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epSender,
                new AsyncCallback(OnReceive), epSender);
        }


    }
    catch (Exception ex)
    {
        IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
        EndPoint epSender = (IPEndPoint)ipeSender;
        byteData = new byte[10];
        serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epSender,
                new AsyncCallback(OnReceive), epSender);
    }

}

As the datagram sent may be very larger too, so that time I have to limit my reading.

Another important point is to send an ACK when the data transfer is completed. The start and end of the transmission is identified by the character "|".

Can any one help me to get rid of this?

Thanks a lot in advance.

Best Regards,
M. J. Jaya Chitra

modified on Thursday, February 19, 2009 6:58 AM

QuestionRead lines in PDF file Pin
abbd19-Feb-09 0:24
abbd19-Feb-09 0:24 
AnswerRe: Read lines in PDF file Pin
Deresen19-Feb-09 1:01
Deresen19-Feb-09 1:01 
GeneralRe: Read lines in PDF file Pin
abbd19-Feb-09 1:22
abbd19-Feb-09 1:22 
GeneralRe: Read lines in PDF file Pin
Pete O'Hanlon19-Feb-09 1:47
mvePete O'Hanlon19-Feb-09 1:47 
QuestionWeather Forecast webservice Pin
ranandbe19-Feb-09 0:11
ranandbe19-Feb-09 0:11 
AnswerRe: Weather Forecast webservice Pin
Eddy Vluggen19-Feb-09 0:43
professionalEddy Vluggen19-Feb-09 0:43 
QuestionVisual Studio Setup project !!! Is it just another kind of Wizard? Pin
Nadia Monalisa18-Feb-09 23:16
Nadia Monalisa18-Feb-09 23:16 
AnswerRe: Visual Studio Setup project !!! Is it just another kind of Wizard? Pin
Calin Tatar18-Feb-09 23:29
Calin Tatar18-Feb-09 23:29 
AnswerRe: Visual Studio Setup project !!! Is it just another kind of Wizard? Pin
Nuri Ismail18-Feb-09 23:32
Nuri Ismail18-Feb-09 23:32 
Questionthread splach screen !!! Pin
mrcooll18-Feb-09 23:03
mrcooll18-Feb-09 23:03 
QuestionAuto Login Pin
Member 299896918-Feb-09 21:39
Member 299896918-Feb-09 21:39 
AnswerRe: Auto Login Pin
musefan18-Feb-09 22:18
musefan18-Feb-09 22:18 
GeneralRe: Auto Login Pin
Member 299896918-Feb-09 22:27
Member 299896918-Feb-09 22:27 
QuestionSocket, Remoting or WCF Pin
yesu prakash18-Feb-09 21:02
yesu prakash18-Feb-09 21:02 
AnswerRe: Socket, Remoting or WCF Pin
Expert Coming18-Feb-09 21:38
Expert Coming18-Feb-09 21:38 
Questioncopy row of one datagrid to another in C# Pin
shafiullah12318-Feb-09 20:30
shafiullah12318-Feb-09 20:30 
AnswerRe: copy row of one datagrid to another in C# Pin
Mycroft Holmes18-Feb-09 21:25
professionalMycroft Holmes18-Feb-09 21:25 

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.