相关疑难解决方法(0)

StreamReader.ReadLine和CR

我在这里很密集吗?StreamReader.ReadLine声明:

一行被定义为一个字符序列,后跟一个换行符("\n"),一个回车符("\ r")或一个回车符后面紧跟一个换行符("\ r \n")

那么,为什么这不能按预期工作呢?

' Server
Dim tcpL as New TcpListener(IPAddress.Any, 5000)
tcpL.Start(1)
Using tcpC as TcpClient = tcpL.AcceptTcpClient(), _
s as NetworkStream = tcpC.GetStream(), _
sr as New StreamReader(s, System.Text.Encoding.ASCII, True)
   Dim message As String = sr.ReadLine()
   Console.WriteLine(message)
End Using
Console.ReadLine()

' Client
Using tcpC as New TcpClient()
  tcpC.Connect(IPAddress.Loopback, 5000)
  Using s as NetworkStream = tcpC.GetStream(), _
  sw as New StreamWriter(s, System.Text.Encoding.ASCII)
     sw.AutoFlush = True
     sw.Write("Hello there!")
     sw.Write(vbCR) ' Note the CR terminator
     Console.ReadLine()
  End …
Run Code Online (Sandbox Code Playgroud)

.net c# sockets vb.net

2
推荐指数
1
解决办法
1978
查看次数

标签 统计

.net ×1

c# ×1

sockets ×1

vb.net ×1