Sinisterly
trying to make a TCP/IP Chat Program - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: Visual Basic & .NET Framework (https://sinister.ly/Forum-Visual-Basic-NET-Framework)
+--- Thread: trying to make a TCP/IP Chat Program (/Thread-trying-to-make-a-TCP-IP-Chat-Program)

Pages: 1 2


trying to make a TCP/IP Chat Program - Blackbone - 08-19-2013

hello guys , im currently making one a chat program so let's get started..
have a look at my code:
Code:
Dim Listener As New TcpListener(65535)
    Dim Client As New TcpClient
    Dim Message As String = ""
    ' Dim ListenerThread As New Thread(New ThreadStart(AddressOf Listening))

    Private Sub btnConnect_Click(sender As Object, e As EventArgs) Handles btnConnect.Click
  '  If cmbAddress.Text.Length < 4 Then
  '  MessageBox.Show("Please Enter a Valid Address", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
  '    Else
  '  If txtName.Text = "" Then
  ' MsgBox("Please enter a name!!", MsgBoxStyle.Critical)
  ' Else
  btnConnect.Text = "Connecting"
  Dim pingresult As String = My.Computer.Network.Ping("192.168.1.2")
  If pingresult = "True" Then
    btnConnect.Text = "Connected"
    Form15.Show()
  Else
    btnConnect.Text = "Disconnected"
    '  End If
    '  End If
  End If
    End Sub
Preview:
[Image: 9A2FDEZ.png]

form15.vb code for Chat room:
Code:
Dim Client As New TcpClient
    Dim Message As String = ""
    Dim Listener As New TcpListener(65535)
    Dim Listener1 As New TcpListener(65534)
    Dim Client1 As New TcpClient
    Dim Message1 As String = ""
    Dim IPAdd As String
    ' Dim clnt As New UNOLibs.Net.ClientClass
    ' Dim clnt2 As New UNOLibs.Net.ClientClass
    '  Dim WithEvents server As UNOLibs.Net.ServerClass
    ' Dim WithEvents server2 As UNOLibs.Net.ServerClass

    Private Sub Listening()
  Listener.Start()
  Listener1.Start()
    End Sub
    Private Sub FlatButton1_Click(sender As Object, e As EventArgs) Handles FlatButton1.Click
  Try
    Client = New TcpClient("192.168.1.2", 65535)
    Dim Writer As New StreamWriter(Client.GetStream())
    Writer.Write(Form5.txtName.Text & ":" & txtmessage.Text)
    Writer.Flush()
    RichTextBox1.Text += (Form5.txtName.Text & ":  " & txtmessage.Text) + vbCrLf
    txtmessage.Text = ""
  Catch ex As Exception
    Console.WriteLine(ex)
    Dim Errorresult As String = ex.Message
    MessageBox.Show(Errorresult & vbCrLf & vbCrLf & "Please Review Client Address", "Error Sending Message", MessageBoxButtons.OK, MessageBoxIcon.Error)
  End Try
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
  If Listener.Pending = True Then
    Message = ""
    Client = Listener.AcceptTcpClient()

    Dim Reader As New StreamReader(Client.GetStream())
    While Reader.Peek > -1
    Message = Message + Convert.ToChar(Reader.Read()).ToString
    End While
    RichTextBox1.ForeColor = Color.Black
    RichTextBox1.Text += Message + vbCrLf
  End If
  If Listener1.Pending = True Then
    Message1 = ""
    Client1 = Listener1.AcceptTcpClient()

    Dim Reader1 As New StreamReader(Client1.GetStream())
    While Reader1.Peek > -1
    Message1 = Message1 + Convert.ToChar(Reader1.Read()).ToString
    End While
    ' Form5.PicClient.Image = StringToBitmap(Message1)
  End If
    End Sub
Preview
[Image: DXgozr2.png]
now when I went to test the application I can connect and form15 will show up then when I try to send a text I get an error:
Code:
No connection could be made because the target machine actively refused it 192.168.1.2:65535

Please review Client Address
help please, what shall I do Sad


RE: trying to make a TCP/IP Chat Program - Bonfire - 08-19-2013

I haven't looked at your code yet, and I'm going on a limb here but... Have you tried forwarding that port?


RE: trying to make a TCP/IP Chat Program - Xanii - 08-19-2013

It means that there is nothing listening at that port to accept the connection. Make sure that your server software is running and accepting connections.


RE: trying to make a TCP/IP Chat Program - Blackbone - 08-19-2013

(08-19-2013, 08:18 PM)Bonfire Wrote: I haven't looked at your code yet, and I'm going on a limb here but... Have you tried forwarding that port?

yes I tried to use one of my port forwarded port and it also didn't work please help, much appreciate it !!

(08-19-2013, 08:37 PM)Xanii Wrote: It means that there is nothing listening at that port to accept the connection. Make sure that your server software is running and accepting connections.
oh!!! I wasn't listening! how dumb am I, but I got a question, if others gonna use this what port should I use :O?


RE: trying to make a TCP/IP Chat Program - Xanii - 08-19-2013

(08-19-2013, 08:37 PM)Blackbone Wrote:
(08-19-2013, 08:18 PM)Bonfire Wrote: I haven't looked at your code yet, and I'm going on a limb here but... Have you tried forwarding that port?

yes I tried to use one of my port forwarded port and it also didn't work please help, much appreciate it !!

(08-19-2013, 08:37 PM)Xanii Wrote: It means that there is nothing listening at that port to accept the connection. Make sure that your server software is running and accepting connections.
oh!!! I wasn't listening! how dumb am I, but I got a question, if others gonna use this what port should I use :O?

It's all up to you, you make the software.


RE: trying to make a TCP/IP Chat Program - Bonfire - 08-19-2013

You might want to refer to this to find an unused port number: http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

You don't have to, but it's a suggestion.

Keep it simple.


RE: trying to make a TCP/IP Chat Program - Blackbone - 08-19-2013

(08-19-2013, 08:48 PM)Bonfire Wrote: You might want to refer to this to find an unused port number: http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

You don't have to, but it's a suggestion.

Keep it simple.

I used Ports 80 & 443 seems legit Biggrin


RE: trying to make a TCP/IP Chat Program - Eternity - 08-19-2013

(08-19-2013, 08:56 PM)Blackbone Wrote:
(08-19-2013, 08:48 PM)Bonfire Wrote: You might want to refer to this to find an unused port number: http://en.wikipedia.org/wiki/List_of_TCP_and_UDP_port_numbers

You don't have to, but it's a suggestion.

Keep it simple.

I used Ports 80 & 443 seems legit Biggrin

It doesn't really matter what port you use, aslong as the server is listening on the same port as the client.


RE: trying to make a TCP/IP Chat Program - Xanii - 08-19-2013

I would also try to make sure to not use a port that is commonly used by something else.


RE: trying to make a TCP/IP Chat Program - tuttomax - 08-20-2013

the ports from 1 to 1024 are system reserved
use port from 49152-65535

for in depth analysis see this: http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.xhtml