|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
multiple tcp connectionsIm 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(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncon.Click If btncon.Text = "Connect" Then servcount = servcount + 1 servers(0, 0) = boxserver.Text con.Connect(boxserver.Text, boxport.Text) Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(": NICK " + txtnick.Text + Chr(13)) con.GetStream.Write(sendBytes, 0, sendBytes.Length) sendBytes = Encoding.ASCII.GetBytes(": USER VITAS 0 * :VITAS IRC" + Chr(13)) con.GetStream.Write(sendBytes, 0, sendBytes.Length) nicklist.Nodes.Add(servcount + ",0", boxserver.Text) btncon.Text = "Disconnect" Else con.Client.Close() btncon.Text = "Connect" End If End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles reader.Tick If con.GetStream.DataAvailable 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_NodeMouseClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles nicklist.NodeMouseClick Dim nodepath() = Split(",", nicklist.SelectedNode.Name) txtstatus.Clear() txtstatus.Text = serverstxt(nodepath(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 My approach would be; the client application would contain an arraylist,
perhaps a hashtable would be better. For each new server connection, I would create a new "IRCClient" class object and add it to the hashtable. Show quoteHide quote "VITAS" <V@w23.de> wrote in message news:43de032b$0$30475$bc1648c9@news.kamp.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(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles btncon.Click > > If btncon.Text = "Connect" Then > > servcount = servcount + 1 > > servers(0, 0) = boxserver.Text > > con.Connect(boxserver.Text, boxport.Text) > > Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(": NICK " + > txtnick.Text > + Chr(13)) > > con.GetStream.Write(sendBytes, 0, sendBytes.Length) > > sendBytes = Encoding.ASCII.GetBytes(": USER VITAS 0 * :VITAS IRC" + > Chr(13)) > > con.GetStream.Write(sendBytes, 0, sendBytes.Length) > > nicklist.Nodes.Add(servcount + ",0", boxserver.Text) > > btncon.Text = "Disconnect" > > Else > > con.Client.Close() > > btncon.Text = "Connect" > > End If > > End Sub > > Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As > System.EventArgs) Handles reader.Tick > > If con.GetStream.DataAvailable 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_NodeMouseClick(ByVal sender As System.Object, ByVal e > As System.Windows.Forms.TreeNodeMouseClickEventArgs) Handles > nicklist.NodeMouseClick > > Dim nodepath() = Split(",", nicklist.SelectedNode.Name) > > txtstatus.Clear() > > txtstatus.Text = serverstxt(nodepath(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 > > >
It's the little things
Windows forms application Threading questions Application health monitoring - how? change value of textbox in datagrid How to get cmdArgs in Windows Application (vs2005) ? Permutation listing Tell to ASP.Net don't watch some web folders Problem while referencing the multiple projects in same solution. Setting Pixel Colors Programmatically in VB 2005 |
|||||||||||||||||||||||