locked
WinForms app and socket connection RRS feed

  • Question

  • Hi,

    I would like to get your opinion on this:

    I have WinForms app and at the main form I'm opening a socket connection to the server.
    This connection should stay open until the user closes the app.

    What's the best way to share the same socket with other forms that may opened from the main form?

    A global variable at the main form will be a good idea??

    Thanks.

    Ubercoder

     

     

    Friday, August 25, 2006 4:29 PM

Answers

  • There are infinite ways to do this, but I would declare
    a static class or class with static members and use that from
    all the forms.
    Friday, August 25, 2006 5:37 PM
    Moderator
  • If you only ever want to have a single socket then statics are an option.  Depending on your requirements I suggest looking into 3-tiered architectures (a heavy weight solution) or possibly a simple implementation the fascade pattern to decouple your logic from your UI.
    Friday, September 1, 2006 4:23 PM

All replies

  • There are infinite ways to do this, but I would declare
    a static class or class with static members and use that from
    all the forms.
    Friday, August 25, 2006 5:37 PM
    Moderator
  • Apologize for the stupid question.

    I know many ways too but for some reason I consider sockets such a delicated matter, that's why I ask if there's any special considerations or I can simply treat it as any other class.

     

    Friday, August 25, 2006 5:55 PM
  • You can treat it as any other class
    Friday, August 25, 2006 9:38 PM
    Moderator
  • If you only ever want to have a single socket then statics are an option.  Depending on your requirements I suggest looking into 3-tiered architectures (a heavy weight solution) or possibly a simple implementation the fascade pattern to decouple your logic from your UI.
    Friday, September 1, 2006 4:23 PM