|
-
Oct 12th, 2008, 08:42 PM
#1
Thread Starter
Member
[02/03] Chat Program help please!
Alright im about to completely lose my mind here, i cant for the life of me get this thing to communicate back and forth current code is
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
listener = New TcpListener(Net.IPAddress.Any, 32111)
listener.Start()
listenThread = New Threading.Thread(AddressOf DoListen)
listenThread.IsBackground = True
listenThread.Start()
txtChat.Text = "Server Started"
userBox.Items.Add(userName.Text)
End Sub
'Server listening
Private Sub DoListen()
Dim sr As StreamReader
Dim sw As StreamWriter
Do
Try
Dim client As Net.Sockets.TcpClient = listener.AcceptTcpClient
sr = New StreamReader(client.GetStream)
Dim username As String = sr.ReadToEnd
userBox.Items.Add(username)
sw = New StreamWriter(client.GetStream)
sw.Write(userBox.Items)
sw.Close()
client = New TcpClient
sr = New StreamReader(client.GetStream)
userBox.Items.Add(sr)
Catch
End Try
Loop
End Sub
'Client Connect
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim client As New TcpClient
Dim sw As StreamWriter
client.Connect("127.0.0.1", 32111)
sw = New StreamWriter(client.GetStream)
sw.Write(userName.Text)
sw.Close()
End Sub
End Class
the bold part is the area im working on, i cant get the server to return a the currently connected clients list to the client, and i cant figure out how to get the client and server to talk for that matter. i feel like im missing a crucial piece here, like how does the stream reader know what stream its reading? I really need some help, ive used my whole entire day to day doing nothing but trying to get this working, please help me...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|