CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 2 of 2 FirstFirst 12
Results 16 to 19 of 19
  1. #16
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: CAsyncSocket and Threads

    Quote Originally Posted by steebu View Post
    ... The "entry" point for the SDK is the execute() function, ...
    I don't understand anything about this statement. What do you mean by "entry point"? What do you mean by SDK ("Software development kit")? What do you mean by the "execute()" function? Is it the thread function we've been discussing? If not, where is it and how is it called?


    Code:
    mSocket s;
    s.Create();
    if( s.Connect( ip, port ) == 0 ) {
      // error check
    }
    s.Send();  // so will the code wait to run this until it runs OnConnect(), which, seemingly never gets called?
    This code can't work, for the reason that the mSocket variable is created on the stack and therefore is destroyed immediately, right after the call to Send().

    It might be helpful if you study this sample: "CHATTER Sample: Demonstrates a Windows Sockets Client Application" at http://msdn.microsoft.com/library/en...fc_chatter.asp

    'CHATTER' is a Windows Sockets Client sample application. It is a single document interface (SDI) application with a splitter window that lets the user send messages to a discussion server ('CHATSRVR', next below), which in turn sends them to multiple other 'CHATTER' users simultaneously.

    Other samples of socket programming are shown in this FAQ: Where can I find examples of socket programs? at http://www.codeguru.com/forum/showthread.php?t=326666

  2. #17
    Join Date
    Jun 2008
    Posts
    12

    Re: CAsyncSocket and Threads

    Quote Originally Posted by MikeAThon View Post
    I don't understand anything about this statement. What do you mean by "entry point"? What do you mean by SDK ("Software development kit")? What do you mean by the "execute()" function? Is it the thread function we've been discussing? If not, where is it and how is it called?
    OK, the software I'm writing this plug-in for ships with an SDK that allows you to build native commands for it. You subclass their Command class, and override their Command::execute() function to have your code do something.

    So ... in my overridden execute() command I'm putting

    mSocket *s = new (mSocket);
    s->Create();
    s->Connect( (LPCTSTR)IP, PORT );
    ...

    Is my assumption below correct?

    because the asynchronous socket may not instantly connect, send data, and close, I will need to kick off a subclassed CWinThread because when the execute() function finishes, everything dies and goes away and I could still be waiting for a connection. Or is that not the case?

    I've read other resources that state that CSocket is bad, bad, bad, so I guess I'll stick with CAsyncSocket.

  3. #18
    Join Date
    Nov 2002
    Location
    California
    Posts
    4,556

    Re: CAsyncSocket and Threads

    Quote Originally Posted by steebu View Post
    ... Is my assumption below correct?

    because the asynchronous socket may not instantly connect, send data, and close, I will need to kick off a subclassed CWinThread because when the execute() function finishes, everything dies and goes away and I could still be waiting for a connection. Or is that not the case?
    I don't know how your execute() function works, so I am really not in a position to answer. If as you say, after execute() finishes everything dies and goes away, and if that also means that any sockets created by you in the execute() function also die and go away, then the answer might be that you cannot accomplish what you want.

    And if everything dies and goes away, then I can't see how a separate CWinThread will help.

    But I suppose I am unclear on what you want. Please explain to us what you are trying to accomplish in the execute() function, and explain the framework in which it exists. We might be able to make better and more specific suggestions. For example, if it is not permissible to wait for a completed network transaction inside the execute() function (i.e, a blocking operation), then perhaps it would be possible to convert the completion notifications (i.e., the callbacks to your OnConnect and OnSend functions) into subsequent calls to different execute() functions.

    Mike

  4. #19
    Join Date
    Jun 2008
    Posts
    12

    Re: CAsyncSocket and Threads

    Quote Originally Posted by MikeAThon View Post
    I don't know how your execute() function works, so I am really not in a position to answer. If as you say, after execute() finishes everything dies and goes away, and if that also means that any sockets created by you in the execute() function also die and go away, then the answer might be that you cannot accomplish what you want.

    And if everything dies and goes away, then I can't see how a separate CWinThread will help.

    But I suppose I am unclear on what you want. Please explain to us what you are trying to accomplish in the execute() function, and explain the framework in which it exists. We might be able to make better and more specific suggestions. For example, if it is not permissible to wait for a completed network transaction inside the execute() function (i.e, a blocking operation), then perhaps it would be possible to convert the completion notifications (i.e., the callbacks to your OnConnect and OnSend functions) into subsequent calls to different execute() functions.

    Mike
    OK, I think we're kind of in the same boat since I don't know know how the execute() function works, either. There is absolutely NO documentation whatsoever for the SDK and I've had to figure things out by looking through headers.

    The only thing I was told by the support/dev folks was "place your code in the overridden execute() function" and that's it. There's no other code to dig through.

    So for every command you want write, subclass their Command class.
    Then there's a bit in the CommandPluginBase::start() function where you must add a line for each command you write:

    m_commands.append( CamServerMsg::createInstance() );

    and that's it. CamServerMsg is my subclassed Command class. The only function that's exposed via headers in their Command class is the execute() function. So "support" told me, "override Command::execute() then add the above line in CommandPluginBase::start() and that's all you have to do."

    The whole idea here is that I want to write a "native command" for the software. It comes with its own scripting language (that looks like MEL, which actually looks like Perl). So the thought was to be able to type into the script editor:

    CamServerMsg "Start" "x:/videos/project/foobar/some_reference_video.avi";

    and hit Enter and the software would then connect to a camera server listening for requests, which would parse the above message into saying "ok, start recording (from an IP camera) and save it to x:/...". Then when the user wants to stop recording he could send

    CamServerMsg "Stop";

    and the software would send a stop message to the server which would then stop recording and save the file.

    Now, unfortunately, there is NO access to GUI elements in the software whatsoever via the SDK. So I can't create my own "record" button or tap into the event handler for existing buttons.

    So ... seemingly this can't be done within the framework of this application? All I have is this execute() function wherein I was told to dump code ... Maybe I'm just up a creek without a paddle ... (or throw in any other unfortunate analogy here)

Page 2 of 2 FirstFirst 12

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured