vbs socket

http://www.bathome.net/thread-423-1-1.html

 

https://files.cnblogs.com/files/developer-ios/mswinsck.ocx_downcc.zip

vbs编写的socket

由于是要用到vb6的控件,即MSWINSCK.OCX,所以如果运行错误,那么下载此附件vb6controls.reg注册
  1. '服务端
  2. 'by wuditom100
  3. '有不足的地方欢迎改进
  4. Dim  revdata
  5. set  sock=WScript.createobject( "MSWinsock.Winsock" ,  "WSEvent_" )
  6. PORT=InputBox ("sever输入要打开的端口:","PORT","")
  7.   sock.LocalPort =PORT
  8.   sock.Listen
  9. Sub WSEvent_ConnectionRequest(requestID)
  10.     sock.Close  
  11.     sock.Accept requestID
  12. End Sub
  13. Sub  WSEvent_DataArrival(bytes)
  14.     MyString= ""
  15.     sock.GetData MyString
  16.     revdata="cilent说:" & MyString
  17.     MsgBox revdata
  18. End Sub
  19. While Not  bClose
  20.   data=InputBox("输入要发送的信息","server发送","")
  21.   If data<>"" then
  22.   sock.senddata data
  23.   WScript.Sleep  1
  24.   Else
  25.   WScript.Quit
  26.   End if
  27. Wend
复制代码
---------------------------------
  1. '客户段
  2. 'by wuditom100
  3. '有不足的地方欢迎改进
  4. Dim  revdata
  5. set  sock=WScript.createobject( "MSWinsock.Winsock" ,  "WSEvent_" )
  6. IP=InputBox("cilent输入连接的IP:","IP","")
  7. PORT=InputBox ("cilent输入连接的PORT:","PORT","")
  8. sock.connect  IP , PORT
  9.   
  10. Sub  WSEvent_Connect()
  11.    wscript.echo  "连接成功!"
  12. end sub
  13. Sub WSEvent_ConnectionRequest(requestID)
  14.    sock.Close  
  15.    sock.Accept requestID
  16. End Sub
  17. Sub  WSEvent_DataArrival(bytes)
  18.     MyString= ""
  19.     sock.GetData MyString
  20.     revdata="server说:"&MyString
  21.     MsgBox revdata
  22. End Sub
  23. While Not  bClose
  24.   data=InputBox("输入要发送的信息","cilent发送","")
  25.   
  26.   If data<>"" Then
  27.         sock.senddata data
  28.         WScript.Sleep  1
  29.     Else
  30.         WScript.Quit
  31.   End if
  32. Wend
复制代码

 

posted @ 2017-01-19 11:58  吃饭了吗  阅读(1458)  评论(0编辑  收藏  举报