mattarnster
New member
- Joined
- Jul 6, 2011
- Messages
- 2
- Programming Experience
- 1-3
So, I am trying to make a server for an Instant Messenger I made in VB.NET, but I can't seem to get it to send the messages it will recieve from clients to the peers.
Here is the code for the server:
I can post the client's code on request as well... But basically, the client will create a TCPClient with the server on the message listen port then write the message. The server is then supposed to figure out if "Mike" or "Matt" is in the string of the message, and then it will determine who is sending it and who is receiving it, in turn sending it to the correct peer.
But the server doesn't seem to send it back, and I cannot work out why. Any help will be greatly appreciated.
Thanks,
Matt
Here is the code for the server:
VB.NET:
Imports System.Net.Sockets
Imports System.Threading
Imports System.IO
Public Class server
Dim AuthListener As New TcpListener(65534)
Dim MsgListener As New TcpListener(65533)
Dim Authclient As New TcpClient
Dim Msgclient As New TcpClient
Dim authdata As String = ""
Dim msgdata As String = ""
Dim matt_ip As String = ""
Dim mike_ip As String = ""
Private Sub server_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim AListThread As New Thread(New ThreadStart(AddressOf alistening))
Dim BListThread As New Thread(New ThreadStart(AddressOf blistening))
AListThread.Start()
BListThread.Start()
End Sub
Private Sub alistening()
AuthListener.Start()
End Sub
Private Sub blistening()
MsgListener.Start()
End Sub
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
If MsgListener.Pending = True Then
msgdata = ""
Msgclient = MsgListener.AcceptTcpClient()
Dim Reader As New StreamReader(Msgclient.GetStream())
While Reader.Peek > -1
msgdata = msgdata + Convert.ToChar(Reader.Read()).ToString
End While
If InStr(1, "$Mike:", msgdata) Then
Try
Msgclient = New TcpClient(matt_ip, 65535)
Dim Writer As New StreamWriter(Msgclient.GetStream())
Writer.Write(msgdata)
Writer.Flush()
Catch ex As Exception
MsgBox("Connection could not be established!")
End Try
ElseIf InStr(1, "$Matt:", msgdata) Then
Try
Msgclient = New TcpClient(mike_ip, 65535)
Dim Writer As New StreamWriter(Msgclient.GetStream())
Writer.Write(msgdata)
Writer.Flush()
Catch ex As Exception
MsgBox("Connection could not be established!")
End Try
End If
End If
End Sub
End Class
But the server doesn't seem to send it back, and I cannot work out why. Any help will be greatly appreciated.
Thanks,
Matt