I get an error saying that the connection was rejected by the target machine here, suggesting that my firewall is working well
How do I make sure that the connection is accepted? It's a chat program (obviously) so I'm going to need to do the same thing on users' computers when it is installed. How do I make this in such a way that the connection will be accepted but leaving security uncomprimised?
vb.net Code:
Imports System.Net.Sockets Public Class QuickChat 'Dim invited As List(Of String) = New List(Of String) 'ip addresses Dim ip(3) As Byte Dim conn As NetworkStream 'Dim s As Socket Dim tcpclient As TcpClient 'Dim tcplistener As TcpListener Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Set up form Dim si As Size = Screen.GetWorkingArea(New Point(1, 1)).Size Me.MaximumSize = New Size(si.Width \ 3, si.Height) Me.Width = Me.MaximumSize.Width 'Retrieve chat IP. Dim ipre As New System.Text.RegularExpressions.Regex("^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$") Dim cip As String = InputBox("Please enter the IP address of the person that you would like to send to.", "Enter IP Address", "0.0.0.0") If Not ipre.IsMatch(cip) Then Me.Close() Exit Sub End If Dim ipbs() As String = cip.Split(".") ip(0) = CByte(ipbs(0)) ip(1) = CByte(ipbs(1)) ip(2) = CByte(ipbs(2)) ip(3) = CByte(ipbs(3)) 'Set up send/recieve tcpclient = New TcpClient() tcpclient.Connect(New Net.IPAddress(ip), 120) conn = tcpclient.GetStream() Me.tmrCheckForMessage.Start() End Sub Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click SendMsg(Me.txtNewMessage.Text) End Sub Private Sub SendMsg(ByVal msg As String) Dim c As Char For Each c In msg conn.WriteByte(AscW(c)) Next conn.WriteByte(0) End Sub Private Function GetMsgIfAny() As String Dim b As Byte = conn.ReadByte() Dim str As String = "" While b > 0 str &= ChrW(b) b = conn.ReadByte() End While Return str End Function Private Sub tmrCheckForMessage_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrCheckForMessage.Tick Dim s As String = GetMsgIfAny() If s = "" Then Exit Sub Me.txtChatLog.Text &= String.Format("{0}{1}{0}{0}", ControlChars.CrLf, s) End Sub End Class





Reply With Quote
