Visual Basic.NET - agregar nombre de archivo

 
Vista:
sin imagen de perfil
Val: 1
Ha aumentado su posición en 14 puestos en Visual Basic.NET (en relación al último mes)
Gráfica de Visual Basic.NET

agregar nombre de archivo

Publicado por paul (1 intervención) el 06/05/2020 22:41:14
hola, quisiera ver si me pueden ayudar:
estoy buscando agregar el nombre del archivo que envio por tcp.. este es el codigo que estoy usando para
enviar (cliente) =

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
Dim TAMAÑOBUFFER As Integer = 1024
Try
    Dim CLIENTE As New TcpClient(Label2.Text, "8080")
    Dim NS As NetworkStream = CLIENTE.GetStream
    Dim FS As New FileStream(TextBox1.Text, FileMode.Open, FileAccess.Read)
    Dim PAQUETES As Integer = CInt(Math.Ceiling(CDbl(FS.Length) / CDbl(TAMAÑOBUFFER)))
    Dim LONGITUDTOTAL As Integer = CInt(FS.Length)
    Dim LONGITUDPAQUETEACTUAL As Integer = 0
    Dim CONTADOR As Integer = 0
    For I As Integer = 0 To PAQUETES - 1
        If LONGITUDTOTAL > TAMAÑOBUFFER Then
            LONGITUDPAQUETEACTUAL = TAMAÑOBUFFER
            LONGITUDTOTAL = LONGITUDTOTAL - LONGITUDPAQUETEACTUAL
        Else
            LONGITUDPAQUETEACTUAL = LONGITUDTOTAL
        End If
        Dim ENVIARBUFFER As Byte() = New Byte(LONGITUDPAQUETEACTUAL - 1) {}
        FS.Read(ENVIARBUFFER, 0, LONGITUDPAQUETEACTUAL)
        NS.Write(ENVIARBUFFER, 0, CInt(ENVIARBUFFER.Length))
 
    Next
    FS.Close()
    NS.Close()
    CLIENTE.Close()
Catch ex As Exception
    MsgBox(ex.Message)
End Try
Me.Close()


y este es el que recibe (SERVER)=
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
Dim CLIENTE As TcpClient
    Dim TAMAÑOBUFFER As Integer = 1024
    Dim ARCHIVORECIBIDO As Byte() = New Byte(TAMAÑOBUFFER - 1) {}
    Dim BYTESRECIBIDOS As Integer
    Dim FIN As Integer = 0
Dim SERVIDOR As New TcpListener(IPAddress.Any, 8080)
 
SERVIDOR.Start()
    While FIN = 0
        Dim NS As NetworkStream = Nothing
    Try
 
        Dim ACEPTA As String = "¿ACEPTA EL ARCHIVO ENTRANTE?"
        Dim TITULO As String = "ARCHIVO ENTRANTE"
        Dim BOTONES As MessageBoxButtons = MessageBoxButtons.YesNo
        Dim RESULTADO As DialogResult
        If SERVIDOR.Pending Then
            CLIENTE = SERVIDOR.AcceptTcpClient
            NS = CLIENTE.GetStream
            RESULTADO = MessageBox.Show(ACEPTA, TITULO, BOTONES)
            If RESULTADO = Windows.Forms.DialogResult.Yes Then
                Dim FICHERORECIBIDO As String = Nothing
                If SaveFileDialog1.ShowDialog = Windows.Forms.DialogResult.OK Then
                    FICHERORECIBIDO = SaveFileDialog1.FileName
                    Process.Start("explorer.exe", SaveFileDialog1.FileName)
                End If
                If FICHERORECIBIDO <> String.Empty Then
                    Dim TOTALBYTESRECIBIDOS As Integer = 0
                    Dim FS As New FileStream(FICHERORECIBIDO, FileMode.OpenOrCreate, FileAccess.Write)
                    While (AYUDAENLINEA(BYTESRECIBIDOS, NS.Read(ARCHIVORECIBIDO, 0, ARCHIVORECIBIDO.Length))) > 0
                        FS.Write(ARCHIVORECIBIDO, 0, BYTESRECIBIDOS)
                        TOTALBYTESRECIBIDOS = TOTALBYTESRECIBIDOS + BYTESRECIBIDOS
                        Me.Hide()
                    End While
                    FS.Close()
                End If
                NS.Close()
                CLIENTE.Close()
 
 
                'SERVIDOR.Stop()
 
                FIN = 1
            End If
        End If
    Catch ex As Exception
        MsgBox(ex.Message)
        End Try
End While
SERVIDOR.Stop()
Me.Hide()
Me.RECIBE()
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder