ironsniper01

ClassForClient.vb

Oct 4th, 2019
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. Imports System.Net.Sockets
  2. Imports System.IO
  3. Public Class ClassforClient
  4. Public Event getMessage(ByVal str As String)
  5. Public Event clientLogout(ByVal client As ClassforClient)
  6. Private sendMessage As StreamWriter
  7. Private listClient As TcpClient
  8. Sub New(ByVal forClient As TcpClient)
  9. listClient = forClient
  10. listClient.GetStream.BeginRead(New Byte() {0}, 0, 0, AddressOf ReadAllClient, Nothing)
  11. End Sub
  12. Private Sub ReadAllClient()
  13. Try
  14. RaiseEvent getMessage(New StreamReader(listClient.GetStream).ReadLine)
  15. listClient.GetStream.BeginRead(New Byte() {0}, 0, 0, New AsyncCallback(AddressOf ReadAllClient), Nothing)
  16. Catch ex As Exception
  17. RaiseEvent clientLogout(Me)
  18. End Try
  19. End Sub
  20. Public Sub Send(ByVal Messsage As String)
  21. sendMessage = New StreamWriter(listClient.GetStream)
  22. sendMessage.WriteLine(Messsage)
  23. sendMessage.Flush()
  24. End Sub
  25. End Class
Advertisement
Add Comment
Please, Sign In to add comment