[.NET] 關於socket server question
請輸入專案類型(網站專案或者應用程式專案):應用程式專案
不好意思,想請教大家關於socket server question
編輯器:vb.net 2010 express
問題 :程式在loop時(while),結果會顯示不出來(畫面當機),但如果拿掉loop(while)就沒問題
程式碼如下:
Public Sub Server_data()
Dim server As Socket = Nothing
server = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
Dim localEndPoint As New IPEndPoint(IPAddress.Parse("172.21.104.147"), 2112)
server.Bind(localEndPoint)
server.Listen(10)
While (True)
Dim success As Boolean
Dim recvbytes(1024) As Byte
Dim acceptsocket As Socket = server.Accept()
success = acceptsocket.Receive(recvbytes)
If (success <> True) Then
TextBox1.Text &= "accept socket is fail" & vbNewLine
Else
TextBox1.Text &= "accept socket is success" & vbNewLine
End If
ListBox1.Items.Insert(0, Encoding.UTF8.GetString(recvbytes))
End While
server.Close()
End Sub
只要將 while 與 end while拿掉,程式就可以正常傳送(不過只能傳一次)
我是打算改成loop,可是畫面會當機然後不動
板上如果有人知道,可否告知一下,謝謝!!!
PS:
想請教板上各位大大,不知是有否有推薦書單可以看
主要我的vb.net大多是用在 網路程式、資料庫、與PLC 這三方面
謝謝!!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 218.164.46.93
推
04/27 21:29, , 1F
04/27 21:29, 1F
→
04/27 21:30, , 2F
04/27 21:30, 2F
→
04/27 21:33, , 3F
04/27 21:33, 3F
推
04/27 22:19, , 4F
04/27 22:19, 4F
→
04/29 23:52, , 5F
04/29 23:52, 5F
→
04/30 12:11, , 6F
04/30 12:11, 6F
→
05/01 18:48, , 7F
05/01 18:48, 7F
→
05/01 18:48, , 8F
05/01 18:48, 8F