CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2007
    Location
    Greece
    Posts
    4

    Multithreading Socket

    Good evening

    Work on a small multithread Server .My Server run properly,Create a Listen thread and for every Client create a WorkThread .In Workthread there is a loop to recv Data .Able to run few Clients.
    When send Data from the Clients to Server receive correctly
    Want to know how can use Form with the workThread ....
    thanks for the time



    p.s sorry for my bad English

  2. #2
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Multithreading Socket

    In VB6? You'd have to post some of your code for us to even begin to help.

    Also, your question isn't clear
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  3. #3
    Join Date
    Mar 2007
    Location
    Greece
    Posts
    4

    Re: Multithreading Socket

    In VB6? You'd have to post some of your code for us to even begin to help.

    Also, your question isn't clear
    Yesterday 08:32 PM

    Good afternoon
    Yes my friend dglienna small multithread in vb 6.
    Here the ThreadListen and Workthread code to saw u how work with thread.
    code
    Public Function ThreadListen(ByVal Param As Long) As Long
    ThreadInit.InitThread
    Dim ClientID As Long
    Dim sAddr As sockaddr_in
    Dim sAddrLen As Long
    Dim IP As String
    TID = GetCurrentThreadId
    Lthread = TID
    listen hListenSck, 10
    Do While True
    sAddrLen = 16
    nRet = accept(hListenSck, sAddr, sAddrLen)
    If nRet <> SOCKET_ERROR Then
    ClientCount = ClientCount + 1
    SockStoreList.Add nRet
    Frmain.thlabel.Caption = ClientCount
    Add_ListData nRet, "127.0.0.1"
    End If

    ClientStore(ClientCount).sock_ID = nRet
    Thread.SetThreadFunc AddressOf WorkthreadTest, 0
    'Through the "thread Param" to pass parameters
    Thread.StartThread ClientCount

    Loop
    End Function
    --Workthread-------
    Public Function WorkthreadTest(ByVal Param As Long) As Long
    ThreadInit.InitThread
    Dim DBuff As String
    Dim ReadBuff As String
    Dim sRec As Long
    TID = GetCurrentThreadId
    Add_DataClientStore Param, nRet, TID
    ThreadList.Add TID
    WriteLog "Client Connected : Socket ID " & nRet & " On Thread ID:" & TID

    Do While True
    DBuff = Space(4096)
    sRec = recv(ClientStore(Param).sock_ID, ByVal DBuff, Len(DBuff), 0)
    If sRec <> 0 And sRec <> SOCKET_ERROR Then
    ReadBuff = ReadBuff & Left(DBuff, sRec)
    WriteData ReadBuff & " " & "Test Hello hello"

    WriteData "Data Received.:" & ReadBuff & " Socket ID..." & ClientStore(Param).sock_ID

    End If
    Loop
    End Function
    Code

    When Click on command(Listen)on FormMain Star a Thread (ThreadListen)to listen for Connections .
    When a client arrive just pass the SocketID to a New Thread(Workthread)
    In this thread run a loop to receive data .
    Until here make many testings and can say able to run 10 Clients(10 threads)
    If the Main form have a second Form(data)how can run this form and communicate with Workthread ?
    Or Just receive on workthread and the Sending on Data form ..
    thanks for the time

  4. #4
    Join Date
    Jan 2006
    Location
    Fox Lake, IL
    Posts
    15,007

    Re: Multithreading Socket

    Pretty complicated in VB6. I'd switch to VB.Net, where it should be a little simpler to test.
    David

    CodeGuru Article: Bound Controls are Evil-VB6
    2013 Samples: MS CODE Samples

    CodeGuru Reviewer
    2006 Dell CSP
    2006, 2007 & 2008 MVP Visual Basic
    If your question has been answered satisfactorily, and it has been helpful, then, please, Rate this Post!

  5. #5
    Join Date
    Mar 2007
    Location
    Greece
    Posts
    4

    Re: Multithreading Socket

    Thankd for the time
    Doesnt matter wil try again

  6. #6
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Multithreading Socket

    I can't tell much about what you are doing from the code posted but I can tell you that I have written a working server in VB6 that handles up to 25 connections without using threading and it works very well.
    Always use [code][/code] tags when posting code.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured