本文介绍了套接字编程错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

当我尝试执行以下代码时,任务栏中没有任何内容。我的意思是,没有执行形式。 :(请帮帮我。



Hello everyone,
while i am trying to execute the following code there is nothing in task bar. I mean, there is no executing form. :( Please help me with this.

Imports System.Net.Sockets
Imports System.Text
Public Class Form1
    Public Shared serverSocket As New TcpListener(System.Net.IPAddress.Any, 8888)
    Public Shared requestCount As Integer
    Public Shared clientSocket As TcpClient
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        serverSocket.Start()
        TextBox1.AppendText("Started..")
        clientSocket = serverSocket.AcceptTcpClient()
        TextBox1.AppendText("Accept connection from client..")
        requestCount = 0
        While (clientSocket.Connected = True)
            Try
                requestCount = requestCount + 1
                Dim networkStream As NetworkStream = clientSocket.GetStream()
                Dim bytesFrom(10024) As Byte
                networkStream.Read(bytesFrom, 0, CInt(clientSocket.ReceiveBufferSize))
                Dim dataFromClient As String = System.Text.Encoding.ASCII.GetString(bytesFrom)
                dataFromClient = dataFromClient.Substring(0, dataFromClient.IndexOf("$"))
                TextBox1.AppendText(dataFromClient)
                Dim serverResponse As String = "Server response " + Convert.ToString(requestCount)
                Dim sendBytes As [Byte]() = Encoding.ASCII.GetBytes(serverResponse)
                networkStream.Write(sendBytes, 0, sendBytes.Length)
                networkStream.Flush()
                TextBox1.AppendText("serverResponse")
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
        End While
    End Sub
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

    End Sub
End Class

推荐答案


这篇关于套接字编程错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 02:19