CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 15 of 15
  1. #1
    Join Date
    Sep 2003
    Posts
    82

    different object when used in other class/object

    I declared
    static SOCKET socket;
    static SOCKET client ;
    in dialog.h

    socket.create()
    socket.listen()

    OnAccept()
    {
    Accept(client,0,0);
    client.Send(data,strlen(data));//it works fine here
    }

    BUT in dialog.cpp(main)
    I start another thread for serial comms...
    in that thread, I tried

    client.Send(data,strlen(data));

    IT doesnt work....
    so I did a check b4 I send.....

    Client.GetPeerName(ClientIP,portnumber);
    // ClientIP=""
    //portnumber=3435973836

    above r the numbers I got
    the obj is not the one that I have in OnAccept.....
    any idea wat happened?

  2. #2
    Join Date
    Sep 2003
    Posts
    82

  3. #3
    Join Date
    Sep 2003
    Posts
    82
    i tried declaring the client socket as extern in the .h

    but once I tried to

    OnAccept()
    {
    server.Accept(Client,0,0)
    //It immdeiately fail a debug assertion
    //error= INVALID_SOCKET
    }

    anyone?

  4. #4
    Join Date
    Sep 2003
    Posts
    82

  5. #5
    Join Date
    Sep 2003
    Posts
    82

  6. #6
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    The code you posted is rather unclear, it won't even compile. What are you trying to do with the followin statements?
    Code:
    static SOCKET socket;
    
    socket.create()
    socket.listen()
    Note that SOCKET is a handle (it is typedef'd as unsigned int), not a class. So socket.create() can't possibly compile.

  7. #7
    Join Date
    Sep 2003
    Posts
    82
    sorry abt that....

    its just to illustrate that its of socket type onli......
    it psuedo code......
    actually code is here..

    http://www.codeguru.com/forum/attach...&postid=822809

  8. #8
    Join Date
    Sep 2003
    Posts
    82

  9. #9
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Your zip archive is damaged...

  10. #10
    Join Date
    Sep 2002
    Posts
    1,747
    The static keyword when applied to an object at file scope means that each translation unit that includes your header will have its own copy of the object to work with. Either make the object a normal global object in your cpp with an extern declaration in the header or singletonise...
    */*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/*/

    "It's hard to believe in something you don't understand." -- the sidhi X-files episode

    galathaea: prankster, fablist, magician, liar

  11. #11
    Join Date
    Sep 2003
    Posts
    82
    I tried declaring the client socket object in .cpp
    and extern in .h

    it can compile and link

    but when I accept the connection,
    the client fail the debug assertion...
    error is the client is a INVALID_SOCKET.

    anyone?
    i'll try to post the code again later.....

  12. #12
    Join Date
    Sep 2003
    Posts
    82

  13. #13
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by hamham

  14. #14
    Join Date
    Sep 2003
    Posts
    82
    its just a dummy expression to up the thread.....

    anyway, here's the code...





    Hi...

    I am very sorry about it....
    I really dont know that an email will be sent to those who have posted to my thread......


    I am using thos post and not a new post so that it wont generate another email to u guys.....

    but i downloaded the code and open...
    it seems to b alright.....
    Attached Files Attached Files
    Last edited by hamham; October 8th, 2003 at 04:00 AM.

  15. #15
    Join Date
    Sep 2002
    Location
    14° 39'19.65"N / 121° 1'44.34"E
    Posts
    9,815
    Originally posted by hamham
    its just a dummy expression to up the thread.....
    May I ask you to drop that habit? Each time you add a dummy post, everybody who has posted to your thread will get an e-mail notification. The reason why you don't get any replies is not that your thread is not seen, but that the information you provide regarding your problem is incomplete or incorrect.

    BTW: The second zip file you posted is damaged too.

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