i'm making program to send picture through socket programming. now my program only can send to 1 destination using destination's IP address.

i'm trying to develop the program, so my program can sending picture to many destination.

with code below, i still cant send to many destination. only the 1st one receive the picture, and when my looping reach the 2nd loop, an error show up and say that my socket still connected with the 1st one.

please help me...

For s As Integer = 0 To (ListBox3.Items.Count - 1)
                konek = True
                user = ListBox1.Items(s)
                namakirim = ListBox2.Items(s)
                address = ListBox3.Items(s) ----> contains IP address
                stat = ListBox4.Items(s)
                staSoc = ListBox5.Items(s)
                If konek = True And stat = "OnLine" And staSoc = "NonAktif" Then
                    konek = False
                    Threading.Thread.Sleep(10000)
                    clientSocke.Connect(address, 15000)
                    serverStream = clientSocke.GetStream()
                    Try
                        '(1) Sending FILE.TXT 
                        Dim fs As New FileStream("C:\Program Aplikasi Greeting Cards\GreetCard\GreetCard\bin\Debug\datakartu.txt", FileMode.Open, FileAccess.Read)
                        Dim wr As New StreamReader(fs)
                        outStream = System.Text.Encoding.ASCII.GetBytes(wr.ReadToEnd)
                        serverStream.Write(outStream, 0, outStream.Length)
                        serverStream.Flush()
                        fs.Close()
                        wr.Close()
                        '(1)done sending file.txt

                        'Read file.txt
                        Dim at As New ArrayList
                        Dim fl As New FileStream("C:\Program Aplikasi Greeting Cards\GreetCard\GreetCard\bin\Debug\datakartu.txt", FileMode.Open, FileAccess.Read)
                        Dim baca As New StreamReader(fl)
                        While (baca.Peek > -1)
                            at.Add(baca.ReadLine)
                        End While
                        Dim sma2 As Integer = at.Count()
                        baca.Close()
                        fl.Close()
                        'done read FILE.TXT

                        If at(2) <> "" Then
                            Dim filestream As FileStream
                            Dim Reader As BinaryReader
                            Dim Writer As BinaryWriter
                            Dim x As Integer
                            Dim z As Integer = 3
                            If at(sma2 - 4) <> 0 Then
                                x = at(0) - at(sma2 - 4) + 1
                            Else
                                x = at(0) - at(sma2 - 2) + 1
                            End If
                            For var = 1 To x
                                Dim PACKET_SIZE As UInt16 = 4096
                                Dim ByteArray() As Byte ' Data buffer
                                filestream = New FileStream(at(z), FileMode.Open, FileAccess.Read)
                                Reader = New BinaryReader(filestream)
                                Writer = New BinaryWriter(clientSocke.GetStream) ' Get socket's stream
                                'send size of file
                                Threading.Thread.Sleep(2000)
                                Writer.Write(CInt(filestream.Length))
                                'Send the file data
                                Do
                                    'read data from file
                                    ByteArray = Reader.ReadBytes(PACKET_SIZE)
                                    'write data to Network Stream
                                    Writer.Write(ByteArray)
                                Loop While ByteArray.Length = PACKET_SIZE
                                'make sure all data is sent
                                Writer.Flush()
                                z = z + 3
                            Next
                        End If
                    Catch ex As Exception
                        MsgBox(ex.ToString)
                    End Try
                                        
                clientSocke.Client.Close()
                Threading.Thread.Sleep(5000)
Next
This article has been dead for over six months. Start a new discussion instead.