I'm trying to get a headstart on a project that im writing for college. I want to write a instant messenger simular to msn messenger. I've got the following so far but its throwing up a load of errors. Can someone take a look please. Thanks
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Net.Sockets
Imports System.Threading
Imports System.IO
Imports System.ComponentModel
Namespace MyNamespace
Public Class Chat
Inherits Form
Public Delegate Sub Invoker(ByVal t As String)
Private thdListener As Thread
Private objListener As TcpListener
Private objClient As TcpClient
Private btSend As New Button()
Private rtbMessage As New RichTextBox()
Private rtbType As New RichTextBox()
Private strFriend As String
Private strMe As String
Public Sub New()
strFriend = "127.0.0.1"
strMe = "Chris"
thdListener = New Thread(New ThreadStart(Me.Listen))
thdListener.Start()
rtbMessage.Dock = DockStyle.Top
rtbMessage.Size = New Size(300, 200)
rtbType.Location = New Point(0, 205)
rtbType.Size = New Size(240, 65)
btSend.Text = "Send"
AddHandler btSend.Click, AddressOf SendText
btSend.Size = New Size(50, 50)
btSend.Location = New Point(240, 205)
Me.Text = ".NET IM"
Me.Size = New Size(300, 300)
AddHandler Me.Closing, AddressOf CloseMe
Me.Controls.Add(btSend)
Me.Controls.Add(rtbMessage)
Me.Controls.Add(rtbType)
End Sub
Private Sub SendText(ByVal Sender As Object, ByVal e As EventArgs)
rtbMessage.Text += strMe + ": " + rtbType.Text + "" & Chr(10) & ""
objClient = New TcpClient(strFriend, 1000)
Dim w As New StreamWriter(objClient.GetStream())
w.Write(rtbType.Text + "" & Chr(10) & "")
w.Flush()
objClient.Close()
rtbType.Text = ""
End Sub
Private Sub Listen()
Dim strTemp As String = ""
objListener = New TcpListener(1000)
objListener.Start()
Do
Dim objClient As TcpClient = objListener.AcceptTcpClient()
Dim objReader As New StreamReader(objClient.GetStream())
While objReader.Peek() <> -1
strTemp += Convert.ToChar(objReader.Read()).ToString()
End While
Dim objParams As Object() = New Object() {strTemp}
strTemp = ""
Me.Invoke(New Invoker(Me.ShowMessage), objParams)
Loop While True <> False
End Sub
Private Sub ShowMessage(ByVal t As String)
rtbMessage.Text += strFriend + ": " + t + "" & Chr(10) & ""
End Sub
Private Sub CloseMe(ByVal Sender As Object, ByVal e As CancelEventArgs)
objListener.[Stop]()
End Sub
Public Shared Sub Main()
Application.Run(New Chat())
End Sub
End Class
End Namespace