Click here to Skip to main content
15,897,315 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
private void startListening()
       {
           NetworkStream stream = clientList.GetStream();
           Byte[] bytes = new Byte[256];
           int k;
           byte[] rdata = null;
           int totalLength = 0;
           try
           {
               while (clientList.Connected)
               {
                   while ((k = stream.Read(bytes, 0, bytes.Length)) != 0)
                   {
                       //rdata = subscribe.Receive(ref ep);
                       totalLength = k;
                       encryptedData = new byte[totalLength];
                       rdata = new byte[(7 * totalLength) / 8];
                       Array.Copy(bytes, 0, encryptedData, 0, totalLength);
                       //rdata = System.Text.Encoding.ASCII.GetBytes(System.Text.Encoding.ASCII.GetString(bytes, 0, k));
                       totalLength = decodeReceivedGsmData(encryptedData, totalLength, rdata);
                       for (int i = 0; i < totalLength; i++)
                           Console.Write(rdata[i] + " ");
                       Console.WriteLine();
                       if ((rdata[0] < 200) && (rdata[0] >= 32))
                       {
                           receiverRC.dataFromGsm = new byte[totalLength]; // copy data from tempbuf to realbuf according to the length
                           for (int i = 0; i < totalLength; i++)
                           {
                               receiverRC.dataFromGsm[i] = rdata[i];
                           }
                           receiverRC.needToSendMsgFromGsmToOtherProjects = true; // set the flag
                       }
                       else if (rdata[0] >= 200)
                       {
                           receiverMC.dataFromGsm = new byte[totalLength]; // copy data from tempbuf to realbuf according to the length
                           for (int i = 0; i < totalLength; i++)
                           {
                               receiverMC.dataFromGsm[i] = rdata[i];
                           }
                           receiverMC.needToSendMsgFromGsmToOtherProjects = true; // set the flag
                       }
                   }

               }

           }
           catch (Exception ex) //not written to serial port, serial port is closed probably
           {

           }
       }

       private byte[] Combine(byte[] a, int length1, byte[] b, int length2)
       {
           byte[] c = new byte[a.Length + b.Length];
           System.Buffer.BlockCopy(a, 0, c, 0, length1);
           System.Buffer.BlockCopy(b, 0, c, length1, length2);
           return c;
       }





problem record

Gsm kapatildi
Exception : System.Threading.ThreadAbortException: Thread was being aborted.
at System.Net.UnsafeNclNativeMethods.OSSOCK.recv(IntPtr socketHandle, Byte* pinnedBuffer, Int32 len, SocketFlags socketFlags)
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode)
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at CardControlProject.ListenerGSM.startListening() in C:\Users\SONY\Desktop\Programs in11 C#\Card Control\SerialPortListener\ListenerGSM.cs:line 108
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in CardControlProject.exe
An exception of type 'System.Threading.ThreadAbortException' occurred in CardControlProject.exe but was not handled in user code
A first chance exception of type 'System.IO.IOException' occurred in System.dll
Exception : System.IO.IOException: Unable to read data from the transport connection: A blocking operation was interrupted by a call to WSACancelBlockingCall. ---> System.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
--- End of inner exception stack trace ---
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at CardControlProject.ListenerGSM.startListening() in C:\Users\SONY\Desktop\Programs in11 C#\Card Control\SerialPortListener\ListenerGSM.cs:line 108
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in System.dll
Exception : System.Threading.ThreadAbortException: Thread was being aborted.
at System.Net.UnsafeNclNativeMethods.OSSOCK.recv(IntPtr socketHandle, Byte* pinnedBuffer, Int32 len, SocketFlags socketFlags)
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode)
at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags)
at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size)
at CardControlProject.ListenerGSM.startListening() in C:\Users\SONY\Desktop\Programs in11 C#\Card Control\SerialPortListener\ListenerGSM.cs:line 108
A first chance exception of type 'System.Threading.ThreadAbortException' occurred in CardControlProject.exe
An exception of type 'System.Threading.ThreadAbortException' occurred in CardControlProject.exe but was not handled in user code
Posted
Comments
ZurdoDev 28-Nov-14 18:21pm    
Search google for the error.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900