Click here to Skip to main content
15,900,907 members
Home / Discussions / C#
   

C#

 
GeneralRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
Jacob D Dixon8-Nov-10 17:56
Jacob D Dixon8-Nov-10 17:56 
GeneralRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
RaviRanjanKr7-Nov-10 16:47
professionalRaviRanjanKr7-Nov-10 16:47 
GeneralRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
Jacob D Dixon8-Nov-10 17:57
Jacob D Dixon8-Nov-10 17:57 
GeneralRe: What am I doing wrong?? Sending serialized objects with Async Sockets.. Pin
Member 1841422-Mar-11 22:48
Member 1841422-Mar-11 22:48 
QuestionUSer Control Error Pin
SRJ925-Nov-10 17:19
SRJ925-Nov-10 17:19 
AnswerRe: USer Control Error Pin
OriginalGriff5-Nov-10 22:54
mveOriginalGriff5-Nov-10 22:54 
AnswerRe: USer Control Error Pin
_Erik_5-Nov-10 23:15
_Erik_5-Nov-10 23:15 
QuestionSocket error on service stop Pin
Jacob D Dixon5-Nov-10 14:40
Jacob D Dixon5-Nov-10 14:40 
Well I'm new to programming using sockets. What i am trying to do is create a client/server model. The client will report into the server every so often, and the server will send back data telling the agent what to do. (Monitoring software).

The problem I am having is closing the socket on the server. I get errors like:
A blocking operation was interrupted by a call to WSACancelBlockingCall

For my code:
while (running)
            {
                try
                {
                    Socket socket = this.listener.Accept();

                    if (socket != null)
                    {
                        Thread handleThread = new Thread(new ParameterizedThreadStart(HandleTheClient));
                        handleThread.Start(socket);
                    }
                }
                catch (Exception ex)
                {
                    Logging.Log(ex.ToString());
                }
            }


Closing:
protected override void OnStop()
        {
            running = false;

            if (listener != null)
            {
                listener.Shutdown(SocketShutdown.Both);
                listener.Close();
            }
        }


Now I know the problem is with;
Socket socket = this.listener.Accept();


But how do I fix this? IS the only way to use AcceptAsync? IF you are wondering why I'm not using that then its because I haven't learned it yet. I need to read up on it first. So can I break this block somehow when the service is trying to stop so the service will stop without error or even stop?
AnswerRe: Socket error on service stop Pin
RaviRanjanKr5-Nov-10 19:08
professionalRaviRanjanKr5-Nov-10 19:08 
GeneralRe: Socket error on service stop [modified] Pin
Jacob D Dixon6-Nov-10 5:32
Jacob D Dixon6-Nov-10 5:32 
QuestionUnit testing Pin
Tichaona J5-Nov-10 7:51
Tichaona J5-Nov-10 7:51 
AnswerRe: Unit testing Pin
fjdiewornncalwe5-Nov-10 8:12
professionalfjdiewornncalwe5-Nov-10 8:12 
AnswerRe: Unit testing Pin
Dave Kreskowiak5-Nov-10 9:43
mveDave Kreskowiak5-Nov-10 9:43 
GeneralRe: Unit testing Pin
Tichaona J5-Nov-10 12:00
Tichaona J5-Nov-10 12:00 
GeneralRe: Unit testing Pin
Pete O'Hanlon5-Nov-10 12:07
mvePete O'Hanlon5-Nov-10 12:07 
GeneralRe: Unit testing Pin
Dave Kreskowiak5-Nov-10 14:08
mveDave Kreskowiak5-Nov-10 14:08 
AnswerRe: Unit testing Pin
David Ewen8-Nov-10 14:07
professionalDavid Ewen8-Nov-10 14:07 
QuestionBadly behaving COM object. Pin
jbradshaw5-Nov-10 3:12
jbradshaw5-Nov-10 3:12 
AnswerRe: Badly behaving COM object. Pin
OriginalGriff5-Nov-10 3:33
mveOriginalGriff5-Nov-10 3:33 
AnswerRe: Badly behaving COM object. Pin
Abhinav S5-Nov-10 3:36
Abhinav S5-Nov-10 3:36 
AnswerRe: Badly behaving COM object. Pin
_Erik_5-Nov-10 3:38
_Erik_5-Nov-10 3:38 
AnswerRe: Badly behaving COM object. Pin
Pete O'Hanlon5-Nov-10 3:43
mvePete O'Hanlon5-Nov-10 3:43 
QuestionWorking with own libaries Pin
neus835-Nov-10 2:28
neus835-Nov-10 2:28 
AnswerRe: Working with own libaries Pin
Abhinav S5-Nov-10 2:45
Abhinav S5-Nov-10 2:45 
AnswerRe: Working with own libaries Pin
Not Active5-Nov-10 2:47
mentorNot Active5-Nov-10 2:47 

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.