|
-
Jul 10th, 2007, 03:19 AM
#1
Thread Starter
Fanatic Member
[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:
Public Class Form1
Dim listeners(9) As Net.Sockets.TcpListener
Dim thrListen As New Threading.Thread(AddressOf DoListen)
Private Sub Form1_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
For i As Integer = 0 To 9
listeners(i).Stop()
listeners(i) = Nothing
Next
thrListen.Abort()
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim basePort As Integer = 44000
For i As Integer = 0 To 9
listeners(i) = New Net.Sockets.TcpListener(Net.IPAddress.Any, basePort + i)
Next
thrListen.Start()
End Sub
Private Sub DoListen()
Dim client As Net.Sockets.TcpClient
Dim sr As IO.StreamReader
Do
For i As Integer = 0 To 9
Try
client = listeners(i).AcceptTcpClient
MsgBox("A")
sr = New IO.StreamReader(client.GetStream)
MessageBox.Show("TcpListener " & i.ToString & " recieved the following:" & Environment.NewLine & sr.ReadToEnd)
Catch
End Try
Next
Loop
End Sub
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|