Results 1 to 5 of 5

Thread: how do you use the winsock control to accept www connections on port 80

  1. #1
    Lively Member
    Join Date
    Jan 99
    Location
    Oshawa, Ontario, Canada
    Posts
    88

    Post

    how do you have the winsock control for use as a webserver??

  2. #2
    New Member
    Join Date
    Apr 99
    Location
    -
    Posts
    7

    Post

    Hello, I wouldn't have the foggiest idea, but here's a cloudy one:

    Winsock.localport = 80
    Winsock.listen

    whenever something connects
    accept the connection & send the strings of a html file e.g.

    Dim file as string
    file = "<html><body><h1>HI THERE</h1></body></html>"

    Winsock.senddata file

    Hope this works 4 u, might need some shaving
    - Wax



  3. #3
    Fanatic Member
    Join Date
    Jun 99
    Location
    California, USA
    Posts
    662

    Post

    that probably won't work. i have compleatly written a webserver already. try
    control.localport = 80
    control.listen

    Private Sub control_ConnectRequest(RequestId as whatever)
    control.close
    control.Accept RequestId
    End Sub

    Private Sub control_DataArrival(Length as whatever)
    control.SendData YourData
    End Sub

    Private Sub control_SendComplete()
    control.Close
    Ens Sub

    This is a modified version of my code. I might recommend using a control array so as you can have multiple connections simultaniously. For more info on the HTTP protocal goto http://www.jmarshall.com/easy/http/

  4. #4
    New Member
    Join Date
    Jul 99
    Posts
    1

    Post

    For mutliple connections, the best way to do it is this: Say you are using a Winsock control named Winsock1, which is the control listening for a connection request. Give that an index value of 0, so it is Winsock1(0). Give all other connections of that winsock control incremental Indexes...a way to show that in code is:
    Option Explicit
    Const conPort as Integer = 80

    Private Sub Form_Load()
    Winsock1(0).LocalPort = conPort
    Winsock1(0).Listen
    End Sub

    Private Sub Winsock1_ConnectionRequest(Index as Integer)
    Const conPort as Integer = 80
    Static intMax as Integer
    If Index = 0 Then
    intMax = intMax + 1
    Load Winsock2(intMax)
    Winsock2(intMax).LocalPort = conPort
    Winsock2(intMax).Accept requestID
    End If
    End Sub

    If a connection ever closes, remember to do something like this to ensure that the winsock control can be used again for that number if you reset your server.

    Private Sub Winsock1_Close(Index as Integer)
    Unload Winsock1(Index)
    End Sub


  5. #5
    New Member
    Join Date
    Jan 99
    Location
    Franklin, WI, USA
    Posts
    8

    Post

    Here is my code, but it doesn't work... PLEASE help...

    Private Sub Form_Load()
    Winsock1.LocalPort = 80
    Winsock1.Listen
    End Sub

    Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
    Winsock1.Close
    Winsock1.Accept requestID
    End Sub

    Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
    Dim MyData As String
    MyData = "IT WORKS!!!"
    MyData = MyData & vbCrLf & "<br>The time is now " & Time$
    Winsock1.SendData MyData
    End Sub

    Private Sub Winsock1_SendComplete()
    Winsock1.Close
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •