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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. How to "kill" a socket

How to "kill" a socket

Scheduled Pinned Locked Moved C#
comhelptutorialquestion
1 Posts 1 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.
  • N Offline
    N Offline
    nahumtakum
    wrote on last edited by
    #1

    I have created the following class: public class Mobile : IDisposable { private TcpListener tcpListener public Socket sockToClient } public Mobile (string Remote_Ep) { IPHostEntry hoen = Dns.Resolve(Remote_Ep); IPEndPoint ep = new IPEndPoint(hoen.AddressList[0], 11000); tcpListener = new TcpListener(ep); tcpListener.Start(); Thread t = new Thread( new ThreadStart(thread_proc_IO) ); t.Start(); } private void thread_proc_IO() { bool fDone = false; while( !fDone ) { try { Console.Write("\n[tid {0}]: Listening on port {1}", GetCurrThread.id(), mb_frs_port ); sockToClient = tcpListener.AcceptSocket(); // @@@ if( sockToClient.Connected ) { Console.Write("\n[tid {0}] Client connected", GetCurrThread.id()); ClientHandler Handler = new ClientHandler(sockToClient); Handler.StartRead(); } } catch (Exception ex) { Console.Write( "\nMobile.thread_proc_IO: [tid {0}] Exception in I/O thread - exiting. " + ex.Message, GetCurrThread.id() ); fDone = true; } } } I am creating several instances of this class, and adds every instance to ArrayList. When I am trying to remove one of the instances, removing it from the ArrayList is not enough I am trying to use dispose, sockToClient_dbg.Shutdown(SocketShutdown.Both), sockToClient.Close(), tcpListener.Stop() but nothing seem to work. I also read about this bug located at www.dotnet247.com/247reference/msgs/1/8442.aspx : "The TCPClient has some known bugs. One of them is that a TCP-connection is NOT closed - when you call .Close(), .Dispose() method. I spent a long time figuring this out. I used Sockets instead at it all worked perfectly...." Does anyone has any idea how to kill this socket ?

    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