上一章对与VB.NET抓取网页乱码的问题的解决方案,今天VB.NET实用教程教你对于VB.NET实现登陆Ftp的方法,快看看学习一下吧。我们都知道远程视频传输可以采用线程下载、图片压缩,还可以考虑先储存进数据库中
VB.NET实用教程代码:
- Private sckConnect As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
- Private RemoteIp As IPEndPoint
- Private thd As Thread
- Private blnExt As Boolean = True
- Private _Quality As Int16 = 50
- Public WriteOnly Property Quality() As Int16 ’这个函数表示服务器要求的图片质量
- Set(ByVal value As Int16)
- _Quality = value
- End Set
- End Property
- Private Sub run()
- Dim byt() As Byte
- Dim stream As MemoryStream
- Dim bmp As Bitmap
- While blnExt
- Try
- bmp = getGrcToBmp() '这是获取图片
- stream = New MemoryStream
- Compress(bmp, stream, _Quality) '这里对图片进行压缩函数
- byt = stream.ToArray
- sckConnect.Send(byt, byt.Length, SocketFlags.None)
- byt.Initialize()
- stream = Nothing
- Thread.Sleep(30) '30毫秒,也就是1秒中传送33次图片
- Catch ex As Exception
- Call Ext()
- End Try
- End While
- End Sub
- Public Sub Send(ByVal ip As String, ByVal port As Integer) '服务器的IP和Port
- Try
- RemoteIp = New IPEndPoint(IPAddress.Parse(ip), port)
- sckConnect.SendTimeout = 100
- sckConnect.Connect(RemoteIp)
- If sckConnect.Connected Then
- thd = New Thread(AddressOf run)
- thd.Start()
- End If
- Catch ex As Exception
- MsgBox(ex.Message)
- Exit Sub
- End Try
- End Sub
- Public Sub Ext()
- Try
- blnExt = False
- thd = Nothing
- sckConnect.Disconnect(True)
- sckConnect.Close()
- Catch ex As Exception
- End Try
- End Sub
以上是VB.NET实用教程对VB.Net实现登陆Ftp的方法的一个讲述,希望大家在平时的工作中总结出更好的方法。
【编辑推荐】