# Re: 关于 winsock UDP 这样写也错吗？

Posted by Roger on December 14, 1998 at 15:55:56:

In Reply to: 关于 winsock UDP 这样写也错吗？ posted by trytsai on December 14, 1998 at 15:38:17:

B程式要加个一小段

set Udp as new Winsock1
Udp.Protocol = sckUDPProtocol
Udp.LocalPort = 1234
Udp.RemoteHost = "127.0.0.1"
Udp.RemotePort = "0"
Udp.SendData vbNull
^^^^^^^^^^^^^^^^^^^^
接收端要先丢个null出去才会收资料.
不知道为什么.

: B 程式:
: Private Sub Form_Load()
: Me.Winsock1.Protocol = sckUDPProtocol
: Me.Winsock1.LocalPort = 1234
: End Sub

: Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
: Dim strData As String
: Winsock1.GetData strData, vbString
: Me.Label1.Caption = Me.Label1.Caption & strData
:
: If (Me.Winsock1.State = sckConnected) Then
: Me.Label2.Caption = Time() & ":Received[" & Me.Label1.Caption & "]"
: Debug.Print Me.Winsock1.RemoteHost
: Debug.Print Me.Winsock1.RemotePort
: Call Me.Winsock1.SendData(Me.Label2.Caption)
: End If
: End Sub

Follow Ups:

- Re: 关于 winsock UDP 这样写也错吗？ trytsai 16:31:52 12/14/98 (2)
  - 错!!!!!!!!!!!!!!!!!!!!!!!!!!!! windows NT user 18:35:00 12/18/98 (1)
    - Re: 错!!!!!!!!!!!!!!!!!!!!!!!!!!!! trytsai 17:04:12 12/28/98 (0)