我在用vb2005的教材上面有一个例子,是一个点对点聊天的例子,我照写下来发现运行以后出现程序无响应求助

来源:互联网 发布:宠物医院数据库设计 编辑:程序博客网 时间:2024/05/17 02:50
Imports System
Imports System.Net
Imports System.Net.Sockets
Imports System.Text
Imports System.Drawing
Imports System.Windows.Forms
Imports System.ComponentModel
Public Class Form1
    Public Function tcplisten(ByVal msg1 As String) As String
        Dim client As TcpClient
        Dim portnumber As Single = 6300
        Dim hostip As IPAddress = IPAddress.Parse("192.168.0.1")
        Dim listener As New TcpListener(hostip, 6300)
        Dim listening As Boolean = True
        Dim msg As Byte()
        Dim read, myme As String
        listener.Start()
        client = New TcpClient(hostip.ToString, portnumber)
        client = listener.AcceptTcpClient
        '定义一个缓冲来存取读取消息
        Dim buffer(4096) As Byte
        '获取数据流
        Dim news As NetworkStream
        news = client.GetStream
        '设置数据流
        msg = System.Text.Encoding.ASCII.GetBytes(msg1)
        '把数据写说数据流()
        news.Write(msg, 0, msg.Length)
        read = news.Read(buffer, 0, buffer.Length)
        myme = System.Text.Encoding.Default.GetString(buffer, 0, read)
        Me.TextBox2.Text = myme
        '关闭数据流和连接
        news.Close()
        client.Close()
        listener.Stop()
    End Function
    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        tcplisten("111")
    End Sub
单瞳执行以后发现运行到       read = news.Read(buffer, 0, buffer.Length)
就没有下文了也没有报错,在线等,求助
 
原创粉丝点击