Results 1 to 3 of 3

Thread: Winsock Socket Closing Issue

  1. #1
    New Member
    Join Date
    Jun 12
    Posts
    2

    Winsock Socket Closing Issue

    Dear All,

    I am designing an application which communication using Ports (8888). I pass a message on port to a remote system and waiting the Remote system response which some time takes more than 5 second to response.

    it is a long time to wait. so I use a timer which wait for 3 seconds if the connection established then it got OFF else application need to close the socket using .close() function.

    I noticed it did not close the port and still wait for resolving the Host.

    Is there any way to give a shutup call to socket closing so that next remote system could be entertained.

    Reg

    Shahid

  2. #2
    New Member
    Join Date
    Jun 12
    Posts
    2

    Re: Winsock Socket Closing Issue

    No One is able to answer. Damn........

  3. #3
    Addicted Member
    Join Date
    Oct 08
    Location
    USA
    Posts
    128

    Re: Winsock Socket Closing Issue

    Im not exactly sure what your question is, but I will attempt to give you an answer.

    I will make a few assumptions and restate a few things for clarity.
    You are connecting to a server on port 8888.
    After you have connected, responses from the server could take upto 5 seconds.
    If it takes to long for a response you want the connection to close.

    I find using the TcpClient Class easier when it comes to networking.

    http://http://msdn.microsoft.com/en-us/library/system.net.sockets.tcpclient.aspx

    Once you have this you can begins an asynchronous read from the tcpclients networkstream.
    http://msdn.microsoft.com/en-us/libr...beginread.aspx

    You can use the networkstream timeout property

    http://msdn.microsoft.com/en-us/library/bk6w7hs8.aspx

    to throw an exception after a specific amount of time. You can close the tcpclient then.

    http://msdn.microsoft.com/en-us/libr...ent.close.aspx

    I hope this helps somewhat.

    By the way I find not many people actually read or reply in the network forum. Try the Visual Basic .Net forum. Its probably not the right place to post networking questions but there are a LOT more people reading it. Just dont post the same question in multiple forums.



    EDIT: I just re-read your post. Are you saying it could take 5 seconds just to connect to the server?

    If that is the case look at the lingerstate property of the tcpclient. That might help.
    Last edited by 2ndmessiah; Jul 11th, 2012 at 11:38 AM.
    Think.... Question.....

Posting Permissions

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