visualbasic tcp如何逐行编写

时间:2016-02-18 17:25:25

标签: vb.net tcp

我想创建一个程序,其他用户可以将数据发送到PC。 我需要一个用户名和密码,但问题是我找不到接受2个tcp数据的代码。

我有变量passwordusername,但是当我开始时,所有文本都被读入username变量。我需要将它分开。

这是我的代码。

Imports System.Net.Sockets
Imports System.Net
Imports MySql.Data.MySqlClient

Public Class Form1
    Dim mysyqlcon As MySqlConnection
    Dim COMMAND As MySqlCommand
    Dim TCPServer As Socket
    Dim TCPListenerz As TcpListener
    Dim username As String
    Dim password As String

    Private Sub TextBox1_TextChanged(sender As Object, e As EventArgs) Handles TextBox1.TextChanged

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        Try
            Dim rcvbytes(TCPServer.ReceiveBufferSize) As Byte
            TCPServer.Receive(rcvbytes)
            username = System.Text.Encoding.ASCII.GetString(rcvbytes)
        Catch ex As Exception
        End Try
        System.Threading.Thread.Sleep(3000)
        Try
            Dim rcvbytes2(TCPServer.ReceiveBufferSize) As Byte
            TCPServer.Receive(rcvbytes2)
            password = System.Text.Encoding.ASCII.GetString(rcvbytes2)
        Catch ex As Exception
        End Try
        Label1.Text = username
        Label2.Text = password
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        TCPListenerz = New TcpListener(IPAddress.Any, 1000)
        TCPListenerz.Start()
        TCPServer = TCPListenerz.AcceptSocket()
        TCPServer.Blocking = False
        Timer1.Enabled = True
    End Sub
End Class

0 个答案:

没有答案