Imports System.Net.Sockets Imports System.Text Public Class irc Private TcpClient As New System.Net.Sockets.TcpClient() Private networkStream As NetworkStream Public Function connect(ByVal server As String, ByVal port As Integer) TcpClient.Connect(server, port) networkStream = TcpClient.GetStream() If networkStream.CanWrite And networkStream.CanRead Then Return "OK" Else If Not networkStream.CanRead Then TcpClient.Close() Return "cannot not write data to this stream" ElseIf Not networkStream.CanWrite Then TcpClient.Close() Return "cannot read data from this stream" Else Return "something batshit crazy happened" End If End If End Function Public Sub write(ByVal data As String) ' Do a simple write. Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes("Is anybody there") NetworkStream.Write(sendBytes, 0, sendBytes.Length) End Sub Public Function read() ' Read the NetworkStream into a byte buffer. Dim bytes(TcpClient.ReceiveBufferSize) As Byte If (TcpClient.Available > 0) Then networkStream.Read(bytes, 0, CInt(TcpClient.ReceiveBufferSize)) ' Output the data received from the host to the console. Dim returndata As String = Encoding.ASCII.GetString(bytes) Return returndata Else Return "NODATA" End If End Function End Class