Help us understand the problem. What is going on with this article?

vbsの作法 その45

概要

vbsの作法調べてみた。
winsock使ってみる。
httpserver作ってみた。

写真

image

環境

windows7 64bit

サンプルコード

Dim oWin
Dim App6
Dim Appflg
Dim html
Const LocalPort = 80
Const sckClosed = 0
Const sckOpen = 1
Const sckListening = 2
Const sckConnectionPending = 3
Const sckResolvingHost = 4
Const sckHostResolved = 5
Const sckConnecting = 6
Const sckConnected = 7
Const sckClosing = 8
Const sckError = 9

Sub App6_exit()
    Appflg = 2
End Sub

Sub App6_ok()
    Set oWin = CreateObject("OSWINSCK.Winsock")
    WScript.ConnectObject oWin, "soc_"
    oWin.LocalPort = LocalPort
    ServerListen
End Sub

Sub soc_OnConnectionRequest(requestID)
    If oWin.State <> sckClosed Then
        oWin.CloseWinsock
    End If
    oWin.Accept(requestID)
    WScript.Sleep 2000
End Sub

Sub soc_OnDataArrival(bytesTotal)
    Dim strData
    strData = ""
    oWin.GetData strData, vbString
    App6.text = strData
    oWin.SendData html
    WScript.Sleep 1000
    oWin.CloseWinsock
End Sub

Sub soc_OnError(Number, Description, SCode, Source, HelpFile, HelpContext, CancelDisplay)
    MsgBox "Server Error " & Number & vbCrLf & Description
    ServerClose()
End Sub

Sub ServerListen()
    If oWin.State <> sckClosed Then
        oWin.CloseWinsock
    End If
    oWin.Listen
End SUb

Sub ServerClose()
    If oWin.State <> sckClosed Then
        oWin.CloseWinsock
    End If
    Set oWin = Nothing
    Wscript.Quit
End SUb

Set App6 = Createobject("OHIcompo6.srv")
WScript.ConnectObject App6, "App6_"
html = "HTTP/1.1 200 OK" & vbcrlf & "Content-Type: text/html" & vbcrlf & "Content-Length: 100" & vbcrlf & vbcrlf & "<!DOCTYPE html><html><body><h1>it's work!</h1></body></html>" & vbcrlf
App6.text = html
Do
    WScript.Sleep(100)
    App6.ping
Loop until Appflg = 2
Set App6 = Nothing


以上。

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした