multiple connections vb.net

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • VITAS

    #1

    multiple connections vb.net

    Hi
    Im trying to program a irc client and got stuck in trying to establish
    multiple server connections. The core problem is, that i dont know how many
    connections i will be using so i tried a array with the type tcpclient, but
    it doesnt work.

    my code:

    Public Class IRCtest



    Private con As New TcpClient <-it works with a normal var but not if i try
    to make it an array.



    Private Sub btncon_Click(By Val sender As System.Object, ByVal e As
    System.EventArg s) Handles btncon.Click

    If btncon.Text = "Connect" Then

    servcount = servcount + 1

    servers(0, 0) = boxserver.Text

    con.Connect(box server.Text, boxport.Text)

    Dim sendBytes As [Byte]() = Encoding.ASCII. GetBytes(": NICK " + txtnick.Text
    + Chr(13))

    con.GetStream.W rite(sendBytes, 0, sendBytes.Lengt h)

    sendBytes = Encoding.ASCII. GetBytes(": USER VITAS 0 * :VITAS IRC" + Chr(13))

    con.GetStream.W rite(sendBytes, 0, sendBytes.Lengt h)

    nicklist.Nodes. Add(servcount + ",0", boxserver.Text)

    btncon.Text = "Disconnect "

    Else

    con.Client.Clos e()

    btncon.Text = "Connect"

    End If

    End Sub

    Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
    System.EventArg s) Handles reader.Tick

    If con.GetStream.D ataAvailable Then <- this is a problem if i use arrays (it
    gives a error saying, that i cant use undeclared values or something like
    that)

    output()

    End If

    End Sub

    Private Sub nicklist_NodeMo useClick(ByVal sender As System.Object, ByVal e
    As System.Windows. Forms.TreeNodeM ouseClickEventA rgs) Handles
    nicklist.NodeMo useClick

    Dim nodepath() = Split(",", nicklist.Select edNode.Name)

    txtstatus.Clear ()

    txtstatus.Text = serverstxt(node path(0), nodepath(1)) <- ive got a tree view
    control and try to make a tree of servers / channels only showing the text
    of the marked one

    End Sub

    End Class



    VITAS


  • Hlrsr

    #2
    Re: multiple connections vb.net

    Why not using an Array List and adding to it the new TcpClient object? Then,
    when the coms between client-server are finished removing it from the list.
    I am doing this with sockets and it works perfect.

    Regards
    GM.


    "VITAS" <V@w23.de> wrote in message
    news:43ddfe25$0 $30469$bc1648c9 @news.kamp.net. ..[color=blue]
    > Hi
    > Im trying to program a irc client and got stuck in trying to establish
    > multiple server connections. The core problem is, that i dont know how[/color]
    many[color=blue]
    > connections i will be using so i tried a array with the type tcpclient,[/color]
    but[color=blue]
    > it doesnt work.
    >
    > my code:
    >
    > Public Class IRCtest
    >
    >
    >
    > Private con As New TcpClient <-it works with a normal var but not if i try
    > to make it an array.
    >
    >
    >
    > Private Sub btncon_Click(By Val sender As System.Object, ByVal e As
    > System.EventArg s) Handles btncon.Click
    >
    > If btncon.Text = "Connect" Then
    >
    > servcount = servcount + 1
    >
    > servers(0, 0) = boxserver.Text
    >
    > con.Connect(box server.Text, boxport.Text)
    >
    > Dim sendBytes As [Byte]() = Encoding.ASCII. GetBytes(": NICK " +[/color]
    txtnick.Text[color=blue]
    > + Chr(13))
    >
    > con.GetStream.W rite(sendBytes, 0, sendBytes.Lengt h)
    >
    > sendBytes = Encoding.ASCII. GetBytes(": USER VITAS 0 * :VITAS IRC" +[/color]
    Chr(13))[color=blue]
    >
    > con.GetStream.W rite(sendBytes, 0, sendBytes.Lengt h)
    >
    > nicklist.Nodes. Add(servcount + ",0", boxserver.Text)
    >
    > btncon.Text = "Disconnect "
    >
    > Else
    >
    > con.Client.Clos e()
    >
    > btncon.Text = "Connect"
    >
    > End If
    >
    > End Sub
    >
    > Private Sub Timer1_Tick(ByV al sender As System.Object, ByVal e As
    > System.EventArg s) Handles reader.Tick
    >
    > If con.GetStream.D ataAvailable Then <- this is a problem if i use arrays[/color]
    (it[color=blue]
    > gives a error saying, that i cant use undeclared values or something like
    > that)
    >
    > output()
    >
    > End If
    >
    > End Sub
    >
    > Private Sub nicklist_NodeMo useClick(ByVal sender As System.Object, ByVal e
    > As System.Windows. Forms.TreeNodeM ouseClickEventA rgs) Handles
    > nicklist.NodeMo useClick
    >
    > Dim nodepath() = Split(",", nicklist.Select edNode.Name)
    >
    > txtstatus.Clear ()
    >
    > txtstatus.Text = serverstxt(node path(0), nodepath(1)) <- ive got a tree[/color]
    view[color=blue]
    > control and try to make a tree of servers / channels only showing the text
    > of the marked one
    >
    > End Sub
    >
    > End Class
    >
    >
    >
    > VITAS
    >
    >[/color]


    Comment

    Working...