www.pudn.com > AVPhone.zip > UDPSocket.ctl
VERSION 5.00
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Begin VB.UserControl UDPSocket
CanGetFocus = 0 'False
ClientHeight = 3600
ClientLeft = 0
ClientTop = 0
ClientWidth = 4800
Enabled = 0 'False
InvisibleAtRuntime= -1 'True
ScaleHeight = 3600
ScaleWidth = 4800
Begin MSWinsockLib.Winsock Winsock1
Left = 1350
Top = 1260
_ExtentX = 593
_ExtentY = 593
_Version = 393216
Protocol = 1
End
End
Attribute VB_Name = "UDPSocket"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
'a simple socket transmission control
'new message arrival
Public Event MessageArrival(ByVal Msg As Byte, Data As Variant)
'send message out
Public Sub SendMessage(ByVal Msg As Byte, Data As Variant)
'store data to byte array
Dim bt() As Byte
bt = Data
'store message handle to last byte
Dim l As Long
l = UBound(bt) + 1
ReDim Preserve bt(l)
bt(l) = Msg
'send it
Winsock1.SendData bt
End Sub
Private Sub UserControl_Initialize()
'use UDP protocol for real time transmission
Winsock1.Protocol = sckUDPProtocol
End Sub
Private Sub UserControl_Paint()
CurrentX = 0
CurrentY = 0
Print "UDP"
Print "Port"
End Sub
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
On Error GoTo ErrorHandle
If Ambient.UserMode Then
'use port 1720 for data transmission
Port = 1720
End If
Exit Sub
ErrorHandle:
MsgBox Err.Description, vbCritical
End Sub
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
oN Error Goto ErrorHandle
'get the data as a byte array
Dim bt() As Byte
Winsock1.GetData bt
Dim l As Long
l = UBound(bt)
'last byte is message handle
Dim b As Byte
b = bt(l)
'restore data
ReDim Preserve bt(l - 1)
'fire receive event
RaiseEvent MessageArrival(b, bt)
ErrorHandle:
End Sub
Public Property Get RemoteHost() As String
RemoteHost = Winsock1.RemoteHost
End Property
Public Property Let RemoteHost(New_Value As String)
Winsock1.RemoteHost = New_Value
End Property
Public Property Get LocalHostName() As String
LocalHostName = Winsock1.LocalHostName
End Property
Public Property Get Port() As Long
Port = Winsock1.LocalPort
End Property
Public Property Let Port(ByVal New_Port As Long)
With Winsock1
.Close
.RemotePort = New_Port
.LocalPort = New_Port
If New_Port Then .Bind
End With
End Property
Public Property Get LocalIP() As String
LocalIP = Winsock1.LocalIP
End Property