Results 1 to 2 of 2

Thread: is this application still up to date or outdated ?

  1. #1

    Thread Starter
    New Member
    Join Date
    Jun 2022
    Posts
    2

    Smile is this application still up to date or outdated ?

    Hi,
    for the last few days I have been struggling to gracfully close connection between multi-thread client server chat application but useless.

    I found this post in this forum

    https://www.vbforums.com/showthread....28#post3640228


    is the technology used until today or outdated ? please if you know a link to a newer version to send it , Thank you.

  2. #2

    Thread Starter
    New Member
    Join Date
    Jun 2022
    Posts
    2

    Re: is this application still up to date or outdated ?

    Hi,
    I worked on this listener alone ( I did not try to connect any clients to it until now).
    I have this problem.

    When starting the listener it started OK without any problem. so I added a stop listener button to this application and I tried to do listener.stop() but it throws an exception System.NullReferenceException

    until now I did not try to connect any client after the listener started.


    How I gracefully shut down this listener without the exception ?

    Code:
    Imports System.IO, System.Net, System.Net.Sockets
    
    Public Class frmServer
        Dim Listener As TcpListener
        Dim Client As TcpClient
        Dim ClientList As New List(Of ChatClient)
        Dim sReader As StreamReader
        Dim cClient As ChatClient
    
        Sub xLoad() Handles Me.Load
            Listener = New TcpListener(IPAddress.Any, 3818)
            Listener.Start()
            xUpdate("Server Started", False)
            Listener.BeginAcceptTcpClient(New AsyncCallback(AddressOf AcceptClient), Listener)
        End Sub
    
        Sub AcceptClient(ByVal ar As IAsyncResult)
            cClient = New ChatClient(Listener.EndAcceptTcpClient(ar))
            AddHandler (cClient.MessageRecieved), AddressOf MessageRecieved
            AddHandler (cClient.ClientExited), AddressOf ClientExited
            ClientList.Add(cClient)
            xUpdate("New Client Joined", True)
            Listener.BeginAcceptTcpClient(New AsyncCallback(AddressOf AcceptClient), Listener)
        End Sub
    
        Sub MessageRecieved(ByVal Str As String)
            xUpdate(Str, True)
        End Sub
    
        Sub ClientExited(ByVal Client As ChatClient)
            ClientList.Remove(Client)
            xUpdate("Client Exited", True)
        End Sub
    
        Delegate Sub _xUpdate(ByVal Str As String, ByVal Relay As Boolean)
        Sub xUpdate(ByVal Str As String, ByVal Relay As Boolean)
            On Error Resume Next
            If InvokeRequired Then
                Invoke(New _xUpdate(AddressOf xUpdate), Str, Relay)
            Else
                txtMainTextBox.AppendText(Str & vbNewLine)
                If Relay Then Send(Str)
            End If
        End Sub
    
        Private Sub TextBox2_KeyDown(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles txtSendTextBox.KeyDown
    
        End Sub
    
        Sub Send(ByVal Str As String)
            For i As Integer = 0 To ClientList.Count - 1
                Try
                    ClientList(i).Send(Str)
                Catch
                    ClientList.RemoveAt(i)
                End Try
            Next
        End Sub
    
        Private Sub btnSend_Click(sender As Object, e As EventArgs) Handles btnSend.Click
            If Me.txtSendTextBox.Text = "" Then
                Exit Sub
            End If
    
            xUpdate("Server Says: " & Me.txtSendTextBox.Text, True)
            txtSendTextBox.Clear()
    
        End Sub
    
        Private Sub btnStopListener_Click(sender As Object, e As EventArgs) Handles btnStopListener.Click
            Listener.Stop()
    'this part stopped the listener but it throws an exception
    
        End Sub
    End Class

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