Advertisement
Guest User

ChatClient.vb

a guest
Dec 11th, 2011
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.21 KB | None | 0 0
  1. Public Class ChatClient
  2.     Dim Tcp_client As System.Net.Sockets.TcpClient
  3.     Dim Server As New ChatServer
  4.     Dim AddIns As New Neuheitenvb
  5.     Dim STW As System.IO.StreamWriter
  6.     Dim STR As System.IO.StreamReader
  7.     Dim IsVerbunden As Boolean = False
  8.     Public ChatName As String
  9.     Public Event NeueNachricht(ByVal c As ChatClient, ByVal sNachricht As String)
  10.     Public Event VerbindungUnterbrochen(ByVal c As ChatClient)
  11.    
  12.     Public ClientID As Integer = 0
  13.  
  14.     Public Sub Start(ByVal TcpClient As System.Net.Sockets.TcpClient)
  15.  
  16.         Me.Tcp_client = TcpClient
  17.         Me.STR = New System.IO.StreamReader(TcpClient.GetStream)
  18.         Me.STW = New System.IO.StreamWriter(TcpClient.GetStream)
  19.         IsVerbunden = True
  20.         ChatName = STR.ReadLine
  21.         ClientID += 1
  22.  
  23.         Dim t As New System.Threading.Thread(AddressOf Lesen)
  24.         t.IsBackground = True
  25.         t.Start()
  26.  
  27.     End Sub
  28.  
  29.     Public Sub schreiben(ByVal sText As String)
  30.         Try
  31.             STW.WriteLine(sText)
  32.             STW.Flush()
  33.         Catch ex As Exception
  34.             VerbindungTrennen()
  35.         End Try
  36.  
  37.     End Sub
  38.  
  39.     Public Sub VerbindungTrennen()
  40.         IsVerbunden = False
  41.         RaiseEvent VerbindungUnterbrochen(Me)
  42.         Tcp_client.Close()
  43.         STW.Close()
  44.         STR.Close()
  45.     End Sub
  46.     Private Sub Lesen(ByVal c As ChatClient)
  47.         Try
  48.             While IsVerbunden = True
  49.                 Dim sAntwort As String = STR.ReadLine
  50.                 If sAntwort = "1" Then
  51.                     'kick
  52.                 ElseIf sAntwort = "2" Then
  53.                     Server.Stopp()
  54.                     Console.WriteLine("End")
  55.                     Exit Sub
  56.  
  57.                 ElseIf sAntwort = "3" Then
  58.                     'Get Users
  59.                     Dim i As Integer = 0
  60.                     AddIns.Get_All_Users()
  61.                     Console.WriteLine(AddIns.AllUsersnames.Length.ToString())
  62.                 ElseIf sAntwort = "4" Then
  63.                 Else
  64.                     RaiseEvent NeueNachricht(Me, sAntwort)
  65.                 End If
  66.  
  67.  
  68.             End While
  69.         Catch ex As Exception
  70.             VerbindungTrennen()
  71.         End Try
  72.  
  73.     End Sub
  74. End Class
  75.  
  76.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement