'发送端代码 Public Class Form1 Inherits System.Windows.Forms.Form 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.ASCII.GetBytes(TextBox1.Text) '对发送的数据进行编码 '*************************** '指定ip和端口 Dim ipHostInfo As System.Net.IPHostEntry = System.Net.Dns.Resolve("d") 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 End Class |