(1) 客户端:
‘发送
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim bytes(1024) As Byte '声明字节数组
Dim sender1 As New System.Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, Net.Sockets.SocketType.Stream, Net.Sockets.ProtocolType.Tcp)
'初始化socket
Dim msg As Byte() = System.Text.Encoding.Unicode.GetBytes(TextBox1.Text)
'对发送的数据进行编码
'***************************
'指定ip和端口
Dim ipHostInfo As System.Net.IPHostEntry = System.Net.Dns.GetHostEntry("192.168.22.131")
Dim ipAddress As System.Net.IPAddress = ipHostInfo.AddressList(0)
Dim ipe As New System.Net.IPEndPoint(ipAddress, 11000)
'**********************
sender1.Connect(ipe) '建立连接
Dim bytesSent As Integer = sender1.Send(msg) '发送数据
'关闭socket
sender1.Shutdown(Net.Sockets.SocketShutdown.Both)
sender1.Close()
End Sub
(2)服务器端:
Dim listener As New System.Net.Sockets.Socket(Net.Sockets.AddressFamily.InterNetwork, N