Question Sockets sending to multiple hosts!

SteboCSC

Member
Joined
Aug 11, 2009
Messages
10
Programming Experience
Beginner
I'm Trying to send a file to multiple hosts by which sites they select on the treeview control. I can't figure out how to set it up. Please Help! Below is the source code.


VB.NET:
Imports System.Threading
Imports System.Net.Sockets
Imports System.Net
Imports System.Text
Imports System.IO


Public Class Form1

    Private Sub btnBrowse_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBrowse.Click
        OpenFileDialog.ShowDialog()
        tbFilename.Text = OpenFileDialog.FileName
    End Sub

    Private Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click

        Dim filebuffer As Byte()
        Dim filestream As Stream
        filestream = File.OpenRead(tbFilename.Text)
        ReDim filebuffer(filestream.Length)

        filestream.Read(filebuffer, 0, filestream.Length)

        Dim len As Long = filestream.Length - 1
        For i As Long = 0 To len
            If i Mod 1000 = 0 Then 'only update UI every 1 Kb copied
                ProgressBar1.Value = i * 100 / len
                Application.DoEvents()
            End If
        Next
        ProgressBar1.Value = 0
        Dim IpHost As IPHostEntry
        IpHost = Dns.GetHostByName(tbServer.Text)
        Dim clientSocket As New TcpClient(CheckedNode(TreeView1), 1234)

        Dim networkStream As NetworkStream
        networkStream = clientSocket.GetStream()
        networkStream.Write(filebuffer, 0, filestream.Length)

    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim factory, group, person As TreeNode
        Dim pintRecords As Integer
        Dim pbndTemp As Binding

        pintRecords = OleDbDataAdapter1.Fill(DsSiteInfo1)

        factory = TreeView1.Nodes.Add("Sites:")

        For Each PRow As DataRow In DsSiteInfo1.Tables("tblSiteInfo").Rows

            group = factory.Nodes.Add(PRow("Site"))

            person = group.Nodes.Add(PRow("IPAddress"))

        Next
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TV1 = TreeView1
        odb = OleDbDataAdapter1
        ds1 = DsSiteInfo1

        Frm2.ShowDialog(Me)

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim A As String
        Dim factory, group, person As TreeNode
        Dim pintRecords As Integer
        Dim pbndTemp As Binding

        A = TreeView1.SelectedNode.Text

        Dim oledbConString As String
        Dim OleConn As New OleDb.OleDbConnection
        Dim DtAdapter As New OleDb.OleDbDataAdapter
        Dim myDs As New DataSet
        OleConn = OleDbConnection1

        Dim countIndex As Integer = 0

        Dim myNode As TreeNode
        For Each myNode In TreeView1.Nodes(0).Nodes
            ' Check whether the tree node is checked.
            If myNode.Checked Then
                ' Set the node's backColor.
                myNode.BackColor = Color.Yellow
                A = myNode.Text()
                Try

                    DtAdapter = New OleDb.OleDbDataAdapter("DELETE * FROM tblSiteInfo WHERE Site='" + A + "'", OleConn)
                    DtAdapter.Fill(myDs)
                    MessageBox.Show("Successfully Deleted", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)

                Catch exp As Exception
                    MessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
                End Try
                countIndex += 1

            Else
                myNode.BackColor = Color.White
            End If
        Next myNode

        OleDbConnection1.Close()
        DtAdapter = Nothing
        myDs = Nothing

    End Sub

    Private Function CheckedNodes(ByVal Node As TreeNode) As String
        Dim Result As String
        If Node.Checked = True Then
            Result = Result & Node.Text & ""
        End If
        Dim N As TreeNode
        For Each N In Node.Nodes
            Result = Result & CheckedNodes(N)
        Next
        Return Result

    End Function

    Private Function CheckedNode(ByVal NodeTree As TreeView) As String
        Dim Result As String
        Dim n As TreeNode
        For Each n In NodeTree.Nodes
            Result = Result & CheckedNodes(n) & ""
        Next
        Return Result.Remove(Result.Length - 0, 0)
    End Function

    Private Sub Button3_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        tbServer.Text = CheckedNode(TreeView1)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

        MsgBox(CheckedNode(TreeView1))

    End Sub
End Class
 
Last edited by a moderator:
Please be a bit more specific. What is the actual problem? You don't know how to send data to more than one client? You don't know how to determine what was selected in a TreeView? Something else?
 
Back
Top