优化VB.NET中的TCP / IP套接字实现

在两台联网的vb.net教程计算机之间进行连接时,我要尝试查找原因,导致〜40ms延迟。 我怀疑服务器应用程序是原因。 我已经使用其c#教程他软件(即Hercules)检查了延迟是否与软件有关,并且我考虑了传输位而不是字符串。 拥塞可能不是原因,但可能是缓冲区和数据包大小-考虑到我在一些早期RFC文档中读到的内容。 我认为延迟是由于服务器而不是客户端,尽管这只是python基础教程我的猜测。 我在ActionScript中对客户端进行了编程。

我问这个问题,因为在关键字TCP / IP上进行了谷歌搜索,而优化会返回有关TCP / IP配置而不是实现的结果。 我是TCP / IP编程的新手,所以我希望对于更高级的程序员来说,错误很容易发现。

服务器应用程序是在VB.NET中编程的:

Public Class Form1

Public Shared remoteAddress As IPAddress = IPAddress.Any
Public Shared port As Int32 = 8080

Public Shared server As New TcpListener(remoteAddress, port)
Public client As TcpClient = Nothing

'....


While (True)
        Try

            Dim buffer(65536) As Byte

            Dim stuff As Integer = client.ReceiveBufferSize
            Console.WriteLine(stuff)

            networkStream.Read(buffer, 0, CInt(client.ReceiveBufferSize))

            Dim dataFromClient As String = System.Text.Encoding.ASCII.GetString(buffer)

            dataFromClient = dataFromClient.Substring(dataFromClient.IndexOf("/") + 1, dataFromClient.IndexOf("\") - 1)


            If dataFromClient Like "/END\" Or dataFromClient Like "/STOP\" Then
                Console.WriteLine("STOP REQUESTED")

                Exit While
            End If

            SetMarker(dataFromClient)

            Console.WriteLine(dataFromClient)

            Dim serverResponse As String = "Receiving marker #" + Convert.ToString(requestCount) + ":  " + dataFromClient
            Dim sendBytes As [Byte]() = System.Text.Encoding.ASCII.GetBytes(serverResponse)
            networkStream.Write(sendBytes, 0, sendBytes.Length)
            networkStream.Flush()
            Console.WriteLine(serverResponse)

        Catch illegalSyntax As System.ArgumentException
            Console.WriteLine("ERROR: Use correct syntax: /command\ Example: /S1\, /STOP\")
        Catch socketEx As SocketException
            Console.WriteLine(SocketError.Interrupted)

        Catch ex As Exception
            MsgBox(ex.ToString)
        End Try

        requestCount = requestCount + 1
    End While
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值