''' <summary> ''' Retourne une partie d'un tableau ''' </summary> ''' Tableau à traiter ''' Offset de départ ''' Longueur ''' <returns></returns> ''' <remarks></remarks> Public Function GetArrayRange(ByVal ptByte As Byte(), ByVal pOffset As Integer, ByVal pLength As Integer) As Byte() Dim ltByte As New List(Of Byte) ltByte.AddRange(ptByte) Return ltByte.GetRange(pOffset, pLength).ToArray End Function
using System; using System.Linq; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Net.Sockets; using System.Net; using System.IO; using System.Xml.Serialization; namespace SmartDeviceProject2 { public partial class Form2 : Form { Socket tcpc = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); TcpClient tcpc1 = new TcpClient(); public Form2() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { TcpListener tcpl = new TcpListener(new IPEndPoint(IPAddress.Parse("192.168.1.171"), 5555)); tcpl.Start() ; tcpc1 = tcpl.AcceptTcpClient() ; tcpl.Stop(); NetworkStream ns = new NetworkStream(tcpc); string[] pl = Directory.GetDirectories("C:\"); string[] kj = Directory.GetFiles("C:\"); XmlSerializer xmls = new XmlSerializer(typeof(Class1)); Class1 class1 = new Class1(); class1.directory = pl; class1.FIles = kj; xmls.Serialize(ns, class1); ns.Close(); string hp = "y"; while (hp == "y") { XmlSerializer xmls1 = new XmlSerializer(typeof(string)); string io = (string)xmls1.Deserialize(ns); switch (io) { case "a": string uy = (string)xmls1.Deserialize(ns); Class1 lk = new Class1(); lk.directory = Directory.GetDirectories(uy); lk.FIles = Directory.GetFiles(uy); xmls.Serialize(ns, lk); ns.Close(); break; } } } }
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre question''' <summary> ''' Flux de buffer, fonctionne comme MemoryStream, mais sans mémorisation des données ''' </summary> ''' <remarks></remarks> Public NotInheritable Class BufferStream Inherits Stream ''' <summary> ''' Tampon ''' </summary> ''' <remarks></remarks> Private mDatas As New List(Of Byte) ''' <summary> ''' Retourne la quantité des données ''' </summary> ''' <value></value> ''' <returns></returns> ''' <remarks></remarks> Public Overrides ReadOnly Property Length() As Long Get Return mDatas.Count End Get End Property ''' <summary> ''' Lit les données dans le tampon ''' </summary> ''' Nombre max d'octets à lire ''' <returns></returns> ''' <remarks></remarks> Public Overloads Overrides Function Read(ByVal pCount As Integer) As Byte() Dim ltData As Byte() Do While mDatas.Count = 0 And Not mIsClose Threading.Thread.Sleep(10) Loop SyncLock mDatas If pCount < mDatas.Count Then ltData = mDatas.GetRange(0, pCount).ToArray mDatas.RemoveRange(0, pCount) Else ltData = mDatas.ToArray mDatas.Clear() End If End SyncLock Return ltData End Function ''' <summary> ''' Ecrit de données dans le flux ''' </summary> ''' Données ''' Offset de début de lecture ''' Longueur de récupération ''' <remarks></remarks> Public Overloads Overrides Sub Write(ByVal buffer() As Byte, ByVal offset As Integer, ByVal count As Integer) SyncLock mDatas mDatas.AddRange(GetArrayRange(buffer, offset, count)) End SyncLock End Sub End Class Public MustInherit Class Stream Inherits IO.Stream Protected mIsClose As Boolean = False Public Overrides ReadOnly Property CanRead() As Boolean Get Return True End Get End Property Public Overrides ReadOnly Property CanSeek() As Boolean Get Return False End Get End Property Public Overrides ReadOnly Property CanWrite() As Boolean Get Return True End Get End Property Public Overrides Sub Flush() 'Ne rien faire End Sub Public Overrides Property Position() As Long Get Return 0 End Get Set(ByVal value As Long) Throw New NotImplementedException End Set End Property Public Overrides Function Read(ByVal buffer() As Byte, ByVal offset As Integer, ByVal count As Integer) As Integer Dim ltData As Byte() ltData = Read(count) ltData.CopyTo(buffer, offset) Return ltData.Length End Function Public MustOverride Overloads Function Read(ByVal pCount As Integer) As Byte() Public Overrides Function Seek(ByVal offset As Long, ByVal origin As System.IO.SeekOrigin) As Long Throw New NotImplementedException End Function Public Overrides Sub SetLength(ByVal value As Long) Throw New NotImplementedException End Sub Public Overloads Sub Write(ByVal buffer() As Byte, ByVal count As Integer) Write(buffer, 0, count) End Sub Public Overloads Sub Write(ByVal buffer() As Byte) Write(buffer, buffer.Length) End Sub Public Overrides Sub Close() mIsClose = True MyBase.Close() End Sub End Class