|
-
Dec 16th, 2012, 11:49 PM
#1
Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient
 Originally Posted by yfzpurgatory
I've been over the code numerous times and I've found no reason for it not to function correctly. Believe I'm just going to move on and hope you decide to rewrite this library at some point in time for C# and/or .NET 4 or 4.5.
That wouldn't help.
-
Dec 17th, 2012, 12:40 AM
#2
Junior Member
Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient
 Originally Posted by jmcilhinney
That wouldn't help.
I don't see why it wouldn't when something about C# is causing it not to function correctly. When I use the library in VB.NET 2010 everything works just fine; zero problems that I haven't fixed myself. When I try the same in C# 4 it's a completely different story. For some reason it just isn't jiving well on these lines:
Code:
Protected Overridable Sub OnConnectionAccepted(ByVal e As ConnectionEventArgs)
Me._synchronisingContext.Post(AddressOf RaiseConnectionAccepted, e)
End Sub
Nothing has been changed, and I know I'm not going crazy. I've ran over the entire library multiple times, and I've very thoroughly went over both the read and send methods line by line to no avail. It has left me completely dumbfounded. The only event that is raised is MessageReceived; both ConnectionClosed and ConnectionAccepted fail, although the client connects.
Last edited by yfzpurgatory; Dec 17th, 2012 at 12:52 AM.
-
Dec 17th, 2012, 09:29 PM
#3
Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient
 Originally Posted by yfzpurgatory
I don't see why it wouldn't when something about C# is causing it not to function correctly. When I use the library in VB.NET 2010 everything works just fine; zero problems that I haven't fixed myself. When I try the same in C# 4 it's a completely different story. For some reason it just isn't jiving well on these lines:
Please stop talking about "C#" in this thread/section. If have a C# question post it here.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Dec 17th, 2012, 10:24 PM
#4
Junior Member
Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient
 Originally Posted by Nightwalker83
Please stop talking about "C#" in this thread/section. If have a C# question post it here.
When the problem is 100% relevant to this topic and this library, no, I don't think I will. What I will do, however, is completely wash my hands of this library. An "MVP" my ass.
-
Jan 9th, 2013, 11:47 AM
#5
Registered User
Re: [VB2008/.NET 3.5] Asynchronous TcpListener & TcpClient
 Originally Posted by jmcilhinney
... nothing is being assigned to the _synchronisingContext field, so you need to work out why. ... SynchronizationContext.Current will return a null reference if you're not using it in either a WinForms or WPF application.
FOREWORD: I opened my account on this forum today for two reasons; 1) to continue discussing a legitimate question in a reasonable tone, and more importantly, to say that this code is the most amazing code I have ever gotten off the internet. Seriously. I'm also a new guy to .net, coming from AmigaBasic (joke, vb6) 1 month ago. In my month of scouring the internet looking and learning to make test programs to learn the language, I have BY FAR learned more from this code than from anything else. Multiple programs from one solution, all while sharing and building a library, with all sorts of fancy commenting and region stuff I never knew existed. The library implements great into other programs, too! THANK YOU so much. I'm a big fan.
That said, I'm working in VB2010 (.net 4.0) and am bumping into a similar issue. The server (as far as I can tell) must be run from a form in order for the SynchronizationContext.Current to not return a null value.
Making a Windows Forms Application launched from sub main (to make it behave as similar as possible to module-based code), I put the following in a blank new form's code (it's basically just a stripped down version of the test server):
Code:
Module serverModule
Public Sub main()
serverWindow.Show()
Application.Run()
End Sub
End Module
Public Class serverWindow
Public WithEvents server As New MessageServer(12345)
Public ReadOnly hosts As New List(Of HostInfo)
Private Sub server_ConnectionAccepted(ByVal sender As Object, ByVal e As Net.ConnectionEventArgs) Handles server.ConnectionAccepted
hosts.Add(e.Host)
End Sub
Private Sub server_MessageReceived(ByVal sender As Object, ByVal e As Net.MessageReceivedEventArgs) Handles server.MessageReceived
server.Send(e.Message)
If e.Message = "exit" Then Me.Close()
End Sub
Private Sub server_ConnectionClosed(ByVal sender As Object, ByVal e As Net.ConnectionEventArgs) Handles server.ConnectionClosed
Dim host = e.Host
hosts.Remove(host)
End Sub
Private Sub MainWindow_FormClosed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles Me.FormClosed
server.Dispose()
Application.Exit()
End Sub
End Class
Clients can connect and talk, the server repeats the chat, and clients can even shut down the server with "exit". The server only has a single blank window running, which I guess could be hidden, but I what I originally wanted was to run the server from a module.
A nearly identical module-based version:
Code:
Module serverModule
Public Sub main()
Application.Run()
End Sub
Public WithEvents server As New MessageServer(12345)
Public ReadOnly hosts As New List(Of HostInfo)
Private Sub server_ConnectionAccepted(ByVal sender As Object, ByVal e As Net.ConnectionEventArgs) Handles server.ConnectionAccepted
hosts.Add(e.Host)
End Sub
Private Sub server_MessageReceived(ByVal sender As Object, ByVal e As Net.MessageReceivedEventArgs) Handles server.MessageReceived
server.Send(e.Message)
If e.Message = "exit" Then shutdown()
End Sub
Private Sub server_ConnectionClosed(ByVal sender As Object, ByVal e As Net.ConnectionEventArgs) Handles server.ConnectionClosed
Dim host = e.Host
hosts.Remove(host)
End Sub
Private Sub shutdown()
server.Dispose()
Application.Exit()
End Sub
End Module
Whenever a client joins, the same line "Me._synchronisingContext.Post(AddressOf RaiseConnectionAccepted, e)" says object reference not set to an instance of an object.
The same error occurs when I try to reproduce the same thing by running the server from a class (without a form). Yet the client seems to run great from a module.
So I guess the question is, would it, and if so, how would it be possible to run a server using your current library without it running from a form?
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
|