==> 本文由 "vinanne68 <vina...@discussions.microsoft.com>"
> 於 news:9D467AAC-F595-430E-BADC-9B7D77A323F1%40microsoft.com 發表
--
風禹科技驗證有限公司 ASP.NET Web News Reader 0.2.6 UTF-8 Beta
網站地圖 http://tlcheng.twbbs.org/wwwmap.htm
流域防洪/區域水資源/徐昇網/玫瑰圖/語音通訊 文章與程式
Basic/Fortran/Windows API/.Net/輔助說明檔 原始碼、文章與討論
微軟程式設計、系統管理使用新技術論壇討論區,網友回覆後即時簡訊、電子郵件通知:
MSDN: http://forums.microsoft.com/msdn-cht/default.aspx?siteid=14
TechNet: http://forums.microsoft.com/technet-cht/default.aspx?siteid=23
--
ASPNET News Reader http://tlcheng.twbbs.org/News/Reader.aspx
RSS 2.0 http://tlcheng.twbbs.org/News/rss2.aspx?Action=List&Newsgroup=microsoft.public.tw.dotnet.languages.vb
"璉璉" 來函:
我使用TcpClient(server, port)來連線
是可以用了
可是有一個問題不知你可幫忙解決
我是按一個按鈕後就送一個詢問出去,後會自動回應。
可是點一點後程式就會當掉,或是傳回來的訊息只接收一半。
程式如 下:
Dim server As String = "192.168.1.50"
Dim port As Int32 = 20000
Dim client As New TcpClient(server, port)
Dim message as string = "TX"
' Translate the passed message into ASCII and store it as a Byte
array.
Dim Message As String = "TX" & Chr(13) & Chr(10)
Dim data As [Byte]() = System.Text.Encoding.ASCII.GetBytes(Message)
' Get a client stream for reading and writing.
' Stream stream = client.GetStream();
Dim stream As NetworkStream = client.GetStream()
' Send the message to the connected TcpServer.
stream.Write(data, 0, data.Length)
Console.WriteLine("Sent: {0}", Message)
' Receive the TcpServer.response.
' Buffer to store the response bytes.
data = New [Byte](256) {}
' String to store the response ASCII representation.
Dim responseData As [String] = [String].Empty
' Read the first batch of the TcpServer response bytes.
Dim bytes As Int32 = stream.Read(data, 0, data.Length)
responseData = System.Text.Encoding.ASCII.GetString(data, 0, bytes)
Console.WriteLine("Received: {0}", responseData)
TextBox1.Text = responseData
' Close everything.
stream.Close()
client.Close()
"璉璉" 來函:
==> 本文由 "vinanne68 <vina...@discussions.microsoft.com>"
> 於 news:ACB6AD33-B170-4F02-8771-D6718D6A56CD%40microsoft.com 發表