Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class ChatClient
- Dim Tcp_client As System.Net.Sockets.TcpClient
- Dim Server As New ChatServer
- Dim AddIns As New Neuheitenvb
- Dim STW As System.IO.StreamWriter
- Dim STR As System.IO.StreamReader
- Dim IsVerbunden As Boolean = False
- Public ChatName As String
- Public Event NeueNachricht(ByVal c As ChatClient, ByVal sNachricht As String)
- Public Event VerbindungUnterbrochen(ByVal c As ChatClient)
- Public ClientID As Integer = 0
- Public Sub Start(ByVal TcpClient As System.Net.Sockets.TcpClient)
- Me.Tcp_client = TcpClient
- Me.STR = New System.IO.StreamReader(TcpClient.GetStream)
- Me.STW = New System.IO.StreamWriter(TcpClient.GetStream)
- IsVerbunden = True
- ChatName = STR.ReadLine
- ClientID += 1
- Dim t As New System.Threading.Thread(AddressOf Lesen)
- t.IsBackground = True
- t.Start()
- End Sub
- Public Sub schreiben(ByVal sText As String)
- Try
- STW.WriteLine(sText)
- STW.Flush()
- Catch ex As Exception
- VerbindungTrennen()
- End Try
- End Sub
- Public Sub VerbindungTrennen()
- IsVerbunden = False
- RaiseEvent VerbindungUnterbrochen(Me)
- Tcp_client.Close()
- STW.Close()
- STR.Close()
- End Sub
- Private Sub Lesen(ByVal c As ChatClient)
- Try
- While IsVerbunden = True
- Dim sAntwort As String = STR.ReadLine
- If sAntwort = "1" Then
- 'kick
- ElseIf sAntwort = "2" Then
- Server.Stopp()
- Console.WriteLine("End")
- Exit Sub
- ElseIf sAntwort = "3" Then
- 'Get Users
- Dim i As Integer = 0
- AddIns.Get_All_Users()
- Console.WriteLine(AddIns.AllUsersnames.Length.ToString())
- ElseIf sAntwort = "4" Then
- Else
- RaiseEvent NeueNachricht(Me, sAntwort)
- End If
- End While
- Catch ex As Exception
- VerbindungTrennen()
- End Try
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement