'xiansr.2014/2/7 vb.net2010 调试通过
创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:成都网站制作、成都网站建设、外贸营销网站建设、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的龙山网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Public Class Form1
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Dim udpClient As New UdpClient(11000)
Try
udpClient.Connect("127.0.0.1", 11000)
Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(RichTextBox1.Text)
udpClient.Send(sendBytes, sendBytes.Length)
Dim RemoteIpEndPoint As New IPEndPoint(IPAddress.Any, 0)
Dim receiveBytes As [Byte]() = udpClient.Receive(RemoteIpEndPoint)
Dim returnData As String = Encoding.ASCII.GetString(receiveBytes)
RichTextBox2.Text = "接收到: " + returnData.ToString()
'Debug.Print(("This message was sent from " + RemoteIpEndPoint.Address.ToString() + " on their port number " + RemoteIpEndPoint.Port.ToString()))
udpClient.Close()
Catch ex As Exception
stop
End Try
End Sub
End Class
你是在哪一句出错?
错误“未将对象引用设置到对象的实例。”一般都是一些Object类型的变量没有初始化(New)导致的
‘客户端向这样写:在窗体说放两个文本框、两个标签、两个按钮、一个列表框
Imports System.Net
Imports System.Net.Sockets
Imports System.IO
Imports System.Threading
Public Class Form1
'网络基础数据流
Private ns As NetworkStream
Private swriter As StreamWriter
Private nsread As StreamReader
Private tcpclient As TcpClient
Private tcpconnected As Boolean = False
Private clisocket As Socket
Private mythread As Thread
'发送
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
If Me.TextBox2.Text "" Then
swriter.WriteLine(Me.TextBox2.Text)
swriter.Flush()
Me.TextBox2.Text = ""
Else
MessageBox.Show("发送信息不能为空!", "错误提示")
End If
End Sub
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'建立连连接
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim ipremote As IPAddress
Dim tcpclient As TcpClient
Try
ipremote = IPAddress.Parse(Me.TextBox1.Text)
Catch ex As Exception
MessageBox.Show("IP地址不合法!", "错误提示")
End Try
Try
tcpclient = New TcpClient(Me.TextBox1.Text, 8000)
ns = tcpclient.GetStream
swriter = New StreamWriter(ns)
Me.StatusBar1.Text = "已经连接上"
Me.Button2.Enabled = False
Me.Button1.Enabled = True
tcpconnected = True
Catch ex As Exception
MessageBox.Show("无法与远程8000端口建立连接!", "错误提示")
End Try
End Sub
Private Sub listen()
Try
Dim tcplistener As New TcpListener(IPAddress.Parse("127.0.0.1"), 8000)
tcplistener.Start()
tcpclient = tcplistener.AcceptTcpClient
ns = tcpclient.GetStream()
nsread = New StreamReader(ns)
While True
Dim msg As String = nsread.ReadLine
If msg = "stop" Then
tcplistener.Stop()
ns.Close()
nsread.Close()
mythread.Abort()
Else
Dim mytime As String = DateTime.Now.ToShortTimeString
Me.ListBox1.Items.Add(mytime + " " + msg)
End If
End While
Catch ex As System.Security.SecurityException
MessageBox.Show("侦听失败!", "错误")
End Try
End Sub
End Class
第一个问题 qq聊天室 必须能 用vb都可以做
第二个问题 vb.net插入数学公式 可以把这些公式封装到一个类中,调用就是了