同步还是异步?
同步简单:
listen
accept
while not bolEnd
   sendto ...
wend
closesocket异步就麻烦了。

解决方案 »

  1.   

    内容太长分开回复
    不如何我联系
    [email protected]
      

  2.   

    在WindowsNT网络中广播消息 
    Windows 9x中有一个WinPopUp.exe可以在一个Windows网络中收发消息。但Windows NT中并未提供该程序。
    利用WIN32 API函数NetMessageBufferSend()可以在一个Windows NT网络中广播一个消息。
    Private Const NERR_Success As Long = 0&
    Private Declare Function NetMessageBufferSend Lib "NETAPI32.DLL" (Server As Any, yToName As Byte, yFromName As Any, yMsg As Byte,ByVal lSize As Long) As Long
    Public Function Sendmsg(strTo As String, strFrom As String,strMessage As String) As Boolean
    Dim bytTo() As ByteDim bytFrom() As ByteDim bytMsg() As Byte
    bytTo = strTo & vbNullCharbytName = strFrom & vbNullChar
    bytMsg = strMessage & vbNullChar
    Sendmsg = (NetMessageBufferSend(ByVal 0&, yToName(0),ByVal 0&, yMsg(0), UBound(yMsg)) = NERR_Success)
    End Function
      

  3.   

    例子没有,但有个模块,是winsock的导出函数。
    http://nowcan.yeah.net
      

  4.   

    Private Declare Function socket Lib "wsock32.dll" (ByVal af As Long, ByVal s_type As Long, ByVal protocal As Long) As Long
    Private Const AF_INET = 2
    Private Const SOCK_STREAM = 1
    Private Declare Function closesocket Lib "wsock32.dll" (ByVal s As Long) As Long
    Private Declare Function WSAStartup Lib "wsock32.dll" (ByVal wversion As Long, lpwsadata As wsadata) As Long
    Private Type wsadata
    wversion As Integer
    whighversion As Integer
    szdescription(0 To 256) As Byte
    szsystemstatus(0 To 128) As Byte
    imaxsockets As Integer
    imaxudpdg As Integer
    lpvendorinfo As Long
    End Type
    Dim sendok As Boolean
    Dim rcptok As Boolean
    Private Declare Function WSAAsyncSelect Lib "wsock32.dll" (ByVal s As Long, ByVal hwnd As Long, ByVal wmsg As Long, ByVal levent As Long) As Long
    Private Const FD_READ = &H1
    Private Declare Function WSACleanup Lib "wsock32.dll" () As Long
    Dim mailok As Boolean
    Private Declare Function connect Lib "wsock32.dll" (ByVal s As Long, addr As sockaddr, ByVal namelen As Long) As Long
    Private Type sockaddr
    sin_family As Integer
    sin_port As Integer
    sin_addr As Long
    sin_zero As String * 8
    End Type
    Private Declare Function gethostbyname Lib "wsock32.dll" (ByVal host_name As String) As Long
    Private Type hostent
    h_name As Long
    h_aliases As Long
    h_addrtype As Integer
    h_length As Integer
    h_addr_list As Long
    End Type
    Dim sll As Long
    Private Declare Function htons Lib "wsock32.dll" (ByVal hostshort As Long) As Integer
    Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
    Private Declare Function send Lib "wsock32.dll" (ByVal s As Long, buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long
    Private Declare Function recv Lib "wsock32.dll" (ByVal s As Long, ByVal buf As Any, ByVal buflen As Long, ByVal flags As Long) As Long
    Private Sub Command1_Click()Dim rc As Long
    Dim xxz As wsadata
    Dim sck As sockaddr
    mailok = False
    rcptok = False
    sendok = False
    Text5.Text = ""
    sll = 0
    sck.sin_family = AF_INET
    sck.sin_addr = getipaddress(Text1.Text)
    sck.sin_port = htons(25)
    sck.sin_zero = String(8, 0)
    rc = WSAStartup(&H101, xxz)
    sll = socket(AF_INET, SOCK_STREAM, 0)
    rc = connect(sll, sck, Len(sck))
    WSAAsyncSelect sll, Text5.hwnd, &H100, FD_READEnd Sub
    Private Function getipaddress(host As String) As Long
    Dim he As Long
    Dim hedesthost As hostent
    Dim addrlist As Long
    Dim rc As Long
    he = gethostbyname(host)
    If he = 0 Then
    MsgBox "主机名错误或网络错误!"
    rc = 0
    Exit Function
    End If
    CopyMemory hedesthost, ByVal he, Len(hedesthost)
    CopyMemory addrlist, ByVal hedesthost.h_addr_list, 4
    CopyMemory rc, ByVal addrlist, hedesthost.h_length
    getipaddress = rc
    End Function Private Sub Text5_KeyDown(KeyCode As Integer, Shift As Integer)
    Dim datareceived As String
    Dim datasend As String
    datareceived = String$(255, Chr(0))
    rc = recv(sll, datareceived, 255, 0)
    If rc <= 0 Then Exit Sub
    Text5.Text = Text5.Text & Left(datareceived, rc)
    If Left(datareceived, 3) = "220" Then datasend = "helo " & Text4.Text & vbCrLf
    If Left(datareceived, 3) = "250" And mailok = False Then
    datasend = "mail from:" & Text4.Text & vbCrLf
    mailok = True
    ElseIf Left(datareceived, 3) = "250" And mailok = True And rcptok = False Then
    datasend = "rcpt to:" & Text2.Text & vbCrLf
    rcptok = True
    ElseIf Left(datareceived, 3) = "250" And rcptok = True And sendok = False Then
    datasend = "data" & vbCrLf
    sendok = True
    ElseIf Left(datareceived, 3) = "250" And sendok = True Then
    Text5.Text = Text5.Text & "邮件发送成功!"
    closesocket sll
    WSACleanup
    Exit Sub
    End If
    If Left(datareceived, 3) = "354" Then datasend = Text3.Text & vbCrLf & "." & vbCrLf
    If Left(datareceived, 1) = "5" Then
    Text5.Text = Text5.Text & "邮件发送失败!"
    closesocket sll
    WSACleanup
    End If
    rc = send(sll, ByVal datasend, Len(datasend), 0)End Sub