Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. How to close a socket which is already open

How to close a socket which is already open

Scheduled Pinned Locked Moved C#
tutorial
10 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sindhutiwari
    wrote on last edited by
    #1

    hi My aim is to close a socket which is already open Socket.close() is raising exception i have tried with few other things still its not closing properly So if any one knows how to do this then plz do let me know regards sindhu tiwari

    its me sid

    N A 2 Replies Last reply
    0
    • S sindhutiwari

      hi My aim is to close a socket which is already open Socket.close() is raising exception i have tried with few other things still its not closing properly So if any one knows how to do this then plz do let me know regards sindhu tiwari

      its me sid

      N Offline
      N Offline
      N a v a n e e t h
      wrote on last edited by
      #2

      Are you calling the ShutDown() method before you make a call to Close() ?

      All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

      S 1 Reply Last reply
      0
      • N N a v a n e e t h

        Are you calling the ShutDown() method before you make a call to Close() ?

        All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

        S Offline
        S Offline
        sindhutiwari
        wrote on last edited by
        #3

        thanks for replying ......................will u plz tell me what this ShutDown() does I would like to brief my problem .. I am having a mobile application ......so if the mobile switches off i need to close the socket at my end ........ can u tell me the best way to do this .....apart from pinging it continously

        its me sid

        N 1 Reply Last reply
        0
        • S sindhutiwari

          thanks for replying ......................will u plz tell me what this ShutDown() does I would like to brief my problem .. I am having a mobile application ......so if the mobile switches off i need to close the socket at my end ........ can u tell me the best way to do this .....apart from pinging it continously

          its me sid

          N Offline
          N Offline
          N a v a n e e t h
          wrote on last edited by
          #4

          sindhutiwari wrote:

          will u plz tell me what this ShutDown() does

          Read it from MSDN[^]

          All C# applications should call Application.Quit(); in the beginning to avoid any .NET problems.- Unclyclopedia My Website | Ask smart questions

          1 Reply Last reply
          0
          • S sindhutiwari

            hi My aim is to close a socket which is already open Socket.close() is raising exception i have tried with few other things still its not closing properly So if any one knows how to do this then plz do let me know regards sindhu tiwari

            its me sid

            A Offline
            A Offline
            AkmalSyed
            wrote on last edited by
            #5

            Hi Sid, Dear I am also working on socket application. Try this statement "objSock.Shutdown(SocketShutdown.Both);"

            S 1 Reply Last reply
            0
            • A AkmalSyed

              Hi Sid, Dear I am also working on socket application. Try this statement "objSock.Shutdown(SocketShutdown.Both);"

              S Offline
              S Offline
              sindhutiwari
              wrote on last edited by
              #6

              hi Akmal Dear,Thanks for ur reply .....i have tried that too ..it dint work perfectly...with my application as u r also working on socket application will u plz tell me how you are determining the status of client i mean to say connected or disconnected ......u r following two way pinging or any other thing plz do let me know

              its me sid

              J 2 Replies Last reply
              0
              • S sindhutiwari

                hi Akmal Dear,Thanks for ur reply .....i have tried that too ..it dint work perfectly...with my application as u r also working on socket application will u plz tell me how you are determining the status of client i mean to say connected or disconnected ......u r following two way pinging or any other thing plz do let me know

                its me sid

                J Offline
                J Offline
                Jamman
                wrote on last edited by
                #7

                Dear Sid, I am using this piece of code in thread.It tells me when client is connected and send data to me. Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 8001); listener.Bind(endpoint); listener.Blocking = true; listener.Listen(0); Socket objSock = listener.Accept(); objSock.Receive(ReceiveData); objSock.Shutdown(SocketShutdown.Both); listener.Close();

                S.Akmal

                1 Reply Last reply
                0
                • S sindhutiwari

                  hi Akmal Dear,Thanks for ur reply .....i have tried that too ..it dint work perfectly...with my application as u r also working on socket application will u plz tell me how you are determining the status of client i mean to say connected or disconnected ......u r following two way pinging or any other thing plz do let me know

                  its me sid

                  J Offline
                  J Offline
                  Jamman
                  wrote on last edited by
                  #8

                  dear Sid. did u try the socket.connected property. It returns a boolean value either u r connected or disconnected.

                  Mr.Syed

                  S 1 Reply Last reply
                  0
                  • J Jamman

                    dear Sid. did u try the socket.connected property. It returns a boolean value either u r connected or disconnected.

                    Mr.Syed

                    S Offline
                    S Offline
                    sindhutiwari
                    wrote on last edited by
                    #9

                    I want to close the Client Socket ....Not the Listner(Server) how u r handeling Client Socket and Socket.Connected returns the previous state

                    its me sid

                    J 1 Reply Last reply
                    0
                    • S sindhutiwari

                      I want to close the Client Socket ....Not the Listner(Server) how u r handeling Client Socket and Socket.Connected returns the previous state

                      its me sid

                      J Offline
                      J Offline
                      Jamman
                      wrote on last edited by
                      #10

                      Send me the Exception text on socket.close().

                      S.Akmal

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups