我在使用TcpClient
和端口127.0.0.1
的本地服务器地址建立与我的1000
的连接时遇到问题。它尝试建立连接,然后发现我的Catch SocketException
无法找到服务器。
我已经设置了断点,并逐行遍历了代码,一旦在按下NetStream = Client.GetStream()
按钮后从我的Try/Catch
内调用了行btnStart
,就会捕获我的异常。表明根本没有建立连接。为什么会这样?
Public Class frmForm1
Dim Client As TcpClient
Dim connection As Socket
Dim NetStream As NetworkStream
Private Sub btnStartClient_Click(sender As Object, e As EventArgs) Handles btnStartClient.Click
Try
txtLog.Text &= "Attempting to connect"
Client = New TcpClient()
Client.Connect(txtAddress.Text, CInt(txtPort.Text))
NetStream = Client.GetStream()
' Catch errors in trying to connect to server
Catch SocketEx As SocketException
txtLog.Text &= "Cannot find server"
End Try
End Sub
它不应引发我的异常,然后创建我的NetworkStream Reader / Writer对象并打印它们已创建。以及设置侦听线程。但是,在行Catch SocketException
NetStream = Client.GetStream()
时,我什至不能走那么远
答案 0 :(得分:1)
您至少需要2个线程。一种用于服务器监听,另一种用于客户端连接。在尝试将客户端连接到服务器之前,请确保在.option("maxRows",1000)
对象(在您的情况下为sdf.writeStream
.outputMode(outputMode)
.format("console")
.option("maxRows",1000) // This is what I want but not sure how to do
.trigger(Trigger.ProcessingTime("2 seconds"))
.start())
)上调用.Start()
。