Click here to Skip to main content
15,915,094 members
Home / Discussions / C#
   

C#

 
AnswerRe: Very Simple HTML Parser C# Pin
V.21-Jul-10 20:59
professionalV.21-Jul-10 20:59 
GeneralRe: Very Simple HTML Parser C# Pin
Luc Pattyn21-Jul-10 21:05
sitebuilderLuc Pattyn21-Jul-10 21:05 
GeneralRe: Very Simple HTML Parser C# Pin
V.21-Jul-10 22:53
professionalV.21-Jul-10 22:53 
QuestionSeriously silly sockets - please assist Pin
GrenMeera21-Jul-10 9:56
GrenMeera21-Jul-10 9:56 
AnswerRe: Seriously silly sockets - please assist Pin
Jimmanuel21-Jul-10 10:34
Jimmanuel21-Jul-10 10:34 
GeneralRe: Seriously silly sockets - please assist Pin
GrenMeera22-Jul-10 5:11
GrenMeera22-Jul-10 5:11 
GeneralRe: Seriously silly sockets - please assist Pin
Jimmanuel22-Jul-10 7:26
Jimmanuel22-Jul-10 7:26 
AnswerRe: Seriously silly sockets - please assist Pin
LimitedAtonement21-Jul-10 10:42
LimitedAtonement21-Jul-10 10:42 
I'm guessing that you have an outstanding call to BeginReceive and calling Close on the Socket. This is probably where you need to research.
I'm also guessing that the reason you're using BeginReceive instead of Receive is because you're running a GUI from this thread and you need to continue to pump messages, right? I've never done this, so I'm not sure what to say. I always try to separate 'View' coding from my 'implementation' coding, so I handle the multithreading like so:

namespace App_Domain
{
    class Program
    {
        static void Main(string[] args)
        {
            System.Net.Sockets.Socket rec_socket = blah, blah,
                send_socket = blah,blah;

            System.Threading.Thread rec_pumper = new System.Threading.Thread(
                new System.Threading.ParameterizedThreadStart(Pump_Messages));
            rec_pumper.Name = "Receive data socket handler";
            rec_pumper.Start(rec_socket);
            //go on about your GUI, and when you're ready to quit,
            //set Keep_Running to false.
        }
        public static bool Keep_Running  = true;
        private const int DATA_LENGTH = 256;
        public readonly static Queue<byte[]> _messages = new System.Collections.Generic.Queue<byte[]>();
        private static void Pump_Messages(object param)
        {
            System.Net.Sockets.Socket connected_socket = param as System.Net.Sockets.Socket;
            if (connected_socket == null)
                throw new System.ArgumentNullException("You must pass a System.Net.Sockets.Socket to me");
            byte[] buffer;
            //establish connection
            while (Keep_Running)
            {
                if (!connected_socket.Connected)
                {
                    break;
                }
                if (connected_socket.Available >= DATA_LENGTH)
                {
                    buffer = new byte[DATA_LENGTH];
                    connected_socket.Receive(buffer);
                    _messages.Enqueue(buffer);
                    buffer = null;
                }
                System.Threading.Thread.Sleep(300);
            }
            if (connected_socket.Connected)
            {
                connected_socket.Close();
            }
            if (Keep_Running)
            {
                //if we're here, we have abnormal termination.
                //log it.
                System.Console.WriteLine("Crap!  Abnormal termination!!  Check the client, he's off his bunker!");
            }
        }
    }
}


I hope this helps.
In Christ,
Aaron Laws

http://ProCure.com

GeneralRe: Seriously silly sockets - please assist Pin
GrenMeera22-Jul-10 5:18
GrenMeera22-Jul-10 5:18 
GeneralRe: Seriously silly sockets - please assist Pin
jschell22-Jul-10 8:38
jschell22-Jul-10 8:38 
QuestionRe: Seriously silly sockets - please assist Pin
Jimmanuel22-Jul-10 9:20
Jimmanuel22-Jul-10 9:20 
QuestionOnly in Release config, SetWindowsHookEx throws error 80004005 Pin
LimitedAtonement21-Jul-10 9:36
LimitedAtonement21-Jul-10 9:36 
AnswerRe: Only in Release config, SetWindowsHookEx throws error 80004005 Pin
Dave Kreskowiak21-Jul-10 10:22
mveDave Kreskowiak21-Jul-10 10:22 
Question? : Operator Pin
I Believe In GOD21-Jul-10 7:00
I Believe In GOD21-Jul-10 7:00 
AnswerRe: ? : Operator Pin
harold aptroot21-Jul-10 7:02
harold aptroot21-Jul-10 7:02 
GeneralRe: ? : Operator Pin
I Believe In GOD21-Jul-10 7:06
I Believe In GOD21-Jul-10 7:06 
GeneralRe: ? : Operator Pin
harold aptroot21-Jul-10 7:13
harold aptroot21-Jul-10 7:13 
GeneralRe: ? : Operator Pin
I Believe In GOD21-Jul-10 7:12
I Believe In GOD21-Jul-10 7:12 
AnswerRe: ? : Operator Pin
Luc Pattyn21-Jul-10 7:02
sitebuilderLuc Pattyn21-Jul-10 7:02 
GeneralRe: ? : Operator Pin
I Believe In GOD21-Jul-10 7:10
I Believe In GOD21-Jul-10 7:10 
GeneralRe: ? : Operator Pin
Roger Wright21-Jul-10 7:54
professionalRoger Wright21-Jul-10 7:54 
GeneralRe: ? : Operator Pin
Luc Pattyn21-Jul-10 8:05
sitebuilderLuc Pattyn21-Jul-10 8:05 
GeneralRe: ? : Operator Pin
Roger Wright21-Jul-10 8:35
professionalRoger Wright21-Jul-10 8:35 
GeneralRe: ? : Operator Pin
Eddy Vluggen21-Jul-10 9:12
professionalEddy Vluggen21-Jul-10 9:12 
GeneralRe: ? : Operator Pin
dan!sh 21-Jul-10 9:18
professional dan!sh 21-Jul-10 9:18 

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.