Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1449

Iocp Server by vb6

$
0
0
"This should be considered a very simple server, with many functions not implemented, and only one framework. I don't think there are many people who need this thing, but I have spent a lot of time researching this thing (I have only seen it for 3 years and practiced it for 30 years to reach today's situation). Therefore, if you download the code, you must give me points."
"Personally, I think the performance of this device should be quite good (the number of bursts should be better than the winsock control). It can achieve 10W of IO per second, and it also has a memory pool implemented to avoid memory fragmentation, which is not bad in terms of stability. However, it is much more difficult to truly write a specific application than the winsock control, but the performance it brings is indeed worth it."

FROM :http://www.vbgood.com/thread-97360-1-1.html

A simple application using I/O Completion Ports and WinSock - CodeProject
https://www.codeproject.com/articles...etion-ports-an

https://www.codeproject.com/articles...r-client-class


form1.frm
Code:

Private Sub Form_Load()
       
        Dim i As Long
       
        If Initsockdll() = False Then
                MsgBox "Init socket dll err"

                End

        End If

        Dbgprint "Successfully initialized Winsock"

        hIOCP = CreateIOCP()

        If hIOCP = 0 Then
                MsgBox "Create IOCP err"

                End

        End If

        Dbgprint "Create IOCP Port Successfully " & hIOCP
        hListenSck = CreateSocket

        If hListenSck = INVALID_SOCKET Then
                MsgBox "Create socket err"

                End

        End If

        Dbgprint "Successfully created the socket"

        If BindServerSocket(hListenSck, 5150, "") = False Then
                MsgBox "bind err"

                End

        End If

        Dbgprint "Bind to Port 5150 Successfully"

        Dim lpThreadId As Long

        Dbgprint "Start worker thread"

        hThread(0) = CreateThread(0, 0, AddressOf ListenFunc, ByVal 0&, 0, lpThreadId) '监听线程
               
        '这里是固定好的12个线程 但是在实际应用中这个应该根据CPU的数目或者实际测试得出具体数目
               
        For i = 1 To 12
                hThread(i) = CreateThread(0, 0, AddressOf WorkFunc, ByVal 0&, 0, lpThreadId)
        Next
       
        Dbgprint "Startup complete port 5150"
End Sub

Private Sub Form_Unload(Cancel As Integer)

        Dim i As Long

        For i = 0 To 13
                TerminateThread hThread(i), 0
        Next

End Sub
Private Sub Timer1_Timer()

        Dim Speed As Long

        txtText6.Text = InterlockedExchange(SendPackageCount, 0)
        txtText7.Text = InterlockedExchange(RecvPackageCount, 0)
        txtText8.Text = Val(txtText6.Text) + Val(txtText7.Text)

        txtText2.Text = Round(InterlockedExchange(SendBytesCount, 0) / 1024, 3)
        txtText3.Text = Round(InterlockedExchange(RecvBytesCount, 0) / 1024, 3)
        txtText9.Text = Val(txtText3.Text) + Val(txtText2.Text) & "KB/S"
        txtText5.Text = PerDataCount
        txtText4.Text = ClientCount
End Sub

Attached Files

Viewing all articles
Browse latest Browse all 1449

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>