vbs聊天工具源码

On Error Resume Next
 LYCIP = "127.0.0.1"
 LYCPort = 9527
 RecvString = chr(49653)&chr(57032)&chr(46287)
 SendString = chr(49653)&chr(57032)&chr(46287)
 Name = ""
 Target = ""
 Set Reminder = Wscript.CreateObject("wscript.shell")
 Set LYC = Wscript.CreateObject("MSWinsock.Winsock", "LYC_")
 
 Function Remind(str, time, title)
  Reminder.Popup str, time, title
 End Function
 
 Sub LYC_ConnectionRequest(args)
  LYC.Close
  LYC.Accept args
 End Sub
 
 Sub LYC_DataArrival(args)
  LYC.GetData RecvString
  If RecvString <> "quit" Then
  Remind RecvString, 2, "来自" & Target
  End If
 End Sub
 
 Function Talk()
  Do
  msg = InputBox(Name & "消息:" & SendString & chr(13) & Target & "消息:" & RecvString,Name,"")
  If msg = False Then
  msg = "quit"
  End If
  If msg <> "" then
  SendString = msg
  LYC.SendData SendString
  WScript.Sleep 5
  End If
  Loop Until SendString = "quit" or RecvString = "quit"
  Msgbox "已断开到" & Target & "的连接"
  WScript.Sleep 5000
 End Function
 
 Function WaitingForClient()
  Remind "正在等待客户端" & chr(13) & "服务器IP:" & LYCIP, 2, "提示"
  While LYC.State <> 7
  WScript.Sleep 500
  Wend
  LYC.SendData SendString
  Remind "已连接客户端", 2, "提示"
 End Function
 
 val = Msgbox("是否新建对话?", vbyesno, "提示")
 If  val= vbyes Then
  Name = "服务器"
  Target = "客户端"
  LYC.LocalPort = LYCPort
  LYC.Listen
  LYCIP = LYC.LocalIP
  WaitingForClient()
  RecvString = ""
  Talk()
 ElseIF val = vbno Then
  Name = "客户端"
  Target = "服务器"
  LYCIP = InputBox("输入服务器的IP","提示","127.0.0.1")
  If LYCIP <> "" Then
  LYC.Connect LYCIP, LYCPort
  SendString = ""
  Talk()
  Else
  Msgbox "没有指定正确IP"
  End If
 End If
 LYC.Close
 Wscript.Quit
 

你可能感兴趣的:(vbs,聊天工具,mswinsock,LYC)