Results 1 to 38 of 38

Thread: [RESOLVED] [2005] TCPListener, Threading, Error.

Threaded View

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2006
    Location
    Anchorage, Alaska
    Posts
    545

    Resolved [RESOLVED] [2005] TCPListener, Threading, Error.

    I have been grabbing code from all over, including this post.

    http://www.vbforums.com/showthread.php?t=451368

    I used a working console code for a client from http://www.eggheadcafe.com/articles/20020323.asp

    But my code below is not accepting the connection.
    The code from eggheadcafe works with the server code from eggheadcafe. So I know I did something wrong in my code for my windows application.

    The complete error message is

    Code:
    System.Net.Sockets.SocketException was unhandled
      ErrorCode=10061
      Message="No connection could be made because the target machine actively refused it"
      Source="System"
      StackTrace:
           at System.Net.Sockets.TcpClient.Connect(String hostname, Int32 port)
           at TCP___CLient.TCPCli.Main() in C:\Documents and Settings\Owner\Local Settings\Application Data\Temporary Projects\TCP - CLient\Module1.vb:line 7
           at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
           at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
           at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
           at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
           at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
           at System.Threading.ThreadHelper.ThreadStart()
    vb Code:
    1. Public Class Form1
    2.     Dim listeners(9) As Net.Sockets.TcpListener
    3.     Dim thrListen As New Threading.Thread(AddressOf DoListen)
    4.  
    5.     Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
    6.  
    7.         For i As Integer = 0 To 9
    8.             listeners(i).Stop()
    9.             listeners(i) = Nothing
    10.         Next
    11.         thrListen.Abort()
    12.  
    13.     End Sub
    14.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    15.         Dim basePort As Integer = 44000
    16.         For i As Integer = 0 To 9
    17.             listeners(i) = New Net.Sockets.TcpListener(Net.IPAddress.Any, basePort + i)
    18.         Next
    19.  
    20.         thrListen.Start()
    21.  
    22.     End Sub
    23.     Private Sub DoListen()
    24.         Dim client As Net.Sockets.TcpClient
    25.         Dim sr As IO.StreamReader
    26.         Do
    27.             For i As Integer = 0 To 9
    28.                 Try
    29.                     client = listeners(i).AcceptTcpClient
    30.                     MsgBox("A")
    31.                     sr = New IO.StreamReader(client.GetStream)
    32.                     MessageBox.Show("TcpListener " & i.ToString & " recieved the following:" & Environment.NewLine & sr.ReadToEnd)
    33.  
    34.                 Catch
    35.  
    36.                 End Try
    37.             Next
    38.         Loop
    39.     End Sub
    40.  
    41. End Class
    Last edited by rack; Jul 17th, 2007 at 10:56 PM.
    Please RATE posts, click the RATE button to the left under the Users Name.

    Once your thread has been answered, Please use the Thread Tools and select RESOLVED so everyone knows your question has been answered.


    "As I look past the light, I see the world I wished tonight, never the less, sleep has come, and death shall soon follow..." © 1998 Jeremy J Swartwood

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