Imports System.Net.Sockets
'to use TcpListen class
Imports System. IO
'use the StreamWriter class
Imports System.Net
'use IPAddress, IPHostEntry etc.
Imports System. When
Public Class Form1
Private swWriter As StreamWriter
'the basic data to the Internet to send data
Private nsStream As NetworkStream
'create send data network based data stream
Dim tcpClient1 As TcpClient
'by it to the remote host for TCP connection
Private tcpConnect As Boolean=False
'defined identifier to say whether to establish a TCP connection
'Private s=New Socket (AddressFamily. InterNetwork, SocketType Stream, ProtocolType. Tcp)
'Dim bytes (1024) As Byte' is used to store the received bytes
'Dim ss As Socket=s.A ccept ()' if the received, create a new Socket connection with
Dim fa As Byte (0 To 29200-1)
Private Sub Button1_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles for. Click
Dim ipRemote As IPAddress
Dim tcpClient As tcpClient
Try
IpRemote=IPAddress. Parse (TextBox1. Text)
Catch
MessageBox. Show (" enter the IP address of the illegal!" , "error!" )
Return
'to judge the legitimacy of the given IP address
End the Try
Try
TcpClient=New tcpClient (TextBox1. Text, 8088)
'apply for a TCP connection to the remote host port 8000
NsStream=tcpClient. GetStream ()
'through the application, and access to transmit data network based data flow
SwWriter=New StreamWriter (nsStream)
'use of access network based data stream to initialize the StreamWriter instance
For the Enabled=False
Button2. Enabled=True
TcpConnect=True
StatusBar1. Text="already connected!"
Catch
MessageBox. Show (" unable to establish a connection to the remote host port 8089!" , "error!" )
Return
End the Try
End Sub
Private Sub Button2_Click (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles Button2. Click
Dim As Integer I
Dim a As Byte=1
'Dim tcpClient As tcpClient
For I=0 To 29200-1
Fa (I)=3
Next
Call sample0 ()
End Sub
Private Sub Form1_Disposed (sender As Object, e the As System. EventArgs) Handles Me. Disposed
If tcpConnect Then
SwWriter. WriteLine (" STOP ")
'send control code
SwWriter. Flush ()
'refresh the current data in a data flow
NsStream. Close ()
SwWriter. Close ()
'removal resources ()
End the If
TcpClient1. SendBufferSize=29200
If Disposing Then
If Not (components Is Nothing) Then
Components. The Dispose ()
End the If
End the If
MyBase. The Dispose (Disposing)
End Sub
Private Sub Form1_Load (ByVal sender As System. Object, ByVal e the As System. EventArgs) Handles MyBase. Load
TcpClient1. SendBufferSize=29200
End Sub
Sub sample0 ()
Dim sample0_Thread As New Thread (AddressOf sample0_printI)
TcpClient1=New TcpClient
TcpClient1. SendBufferSize=29200
Sample0_Thread. Start ()
TextBox3. Text=tcpClient1. SendBufferSize
'the Console. Write (" End ")
End Sub
Sub sample0_printI ()
Dim a As Integer=1
Try
Do
NsStream. Write (fa, 0, 29200)
SwWriter. Flush ()
Loop While a=1
Catch
MessageBox. Show (" unable to establish a connection to the remote host port 8089!" , "error!" )
Return
End the Try
End Sub
The End of the Class
CodePudding user response:
This is allCodePudding user response:
This problem has been so ah, ask back and forth,1. How fast is not you can control, you just write the data to send buffer,
2. Send data is actually a system to take over at the bottom of the
So how fast can play a decisive physical bandwidth, physical network card, and the other receives the speed (because you actually sent each other are not immediately closed, he will go to the receive buffer
CodePudding user response:
3 m/s is already OKMB uplink top skyshatter is 5 m/s, downward 10 m/s
CodePudding user response:
Also see the receiving rate of each other at the same time, if the other party does not timely removing data from the buffer, so the TCP will wait, (no ack reply I have to wait, or send again, or error)If you don't understand, please see the following article
TCP protocol of TCP/IP (3) : flow control (sliding window protocol)
https://blog.csdn.net/wbw1985/article/details/4879224