CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: client/server

  1. #1
    Join Date
    Jul 2001
    Location
    maharashtra,india
    Posts
    181

    client/server

    hi
    i am a client form and an server form.client is passing a query to server and server executing that query.till here it is fine,now i want to pass that whole recordset to client.how can i got suppose rs is my recordset. will this work winsock1.sendata (rs). if it will then what type of datatype should client have to recieve it. and if it wont can u suggest me some other way
    thanx in advance 4 ur help


  2. #2
    Join Date
    Jan 2000
    Location
    Olen, Belgium
    Posts
    2,477

    Re: client/server

    If you are using ADO 2.5+, you can save the recordset (to a file or to a stream), and then send it as text (xml) or binary (ADTG). The latter is smaller, so I would suggest using thatone.

    ' create a new project
    ' add refference to Microsoft ActiveX Dataobject 2.5 (or higher)
    ' put two command buttons on thet form
    ' put two winsock controls on the form

    private Sub Command1_Click()

    ' configure winsock controls and connect to eachother
    Winsock1.RemoteHost = "192.168.2.88"
    Winsock1.RemotePort = 1234

    Winsock2.LocalPort = 1234
    Winsock2.Listen

    Winsock1.Connect

    End Sub

    private Sub Command2_Click()

    Dim rst as new ADODB.Recordset
    Dim myStream as new ADODB.Stream
    Dim strText as string
    Dim strArr() as Byte

    ' create a recordset, add some fields
    rst.Fields.Append "Field1", adBigInt
    rst.Fields.Append "Field2", adBigInt
    rst.Fields.Append "Field3", adBigInt
    rst.Open

    ' fill the recordset
    for t = 1 to 10
    rst.AddNew
    rst("Field1") = Int(Rnd * 10000)
    rst("Field2") = Int(Rnd * 10000)
    rst("Field3") = Int(Rnd * 10000)
    rst.Update
    next t

    ' save the recordset to the stream
    rst.Save myStream, adPersistADTG

    ' save the stream to a byte array
    myStream.Position = 0
    ReDim strArr(myStream.Size)
    strArr() = myStream.Read()

    rst.Close

    ' send the array through the winsock control
    Winsock1.SendData strArr

    End Sub

    private Sub Winsock1_Connect()

    MsgBox "Connected"

    End Sub

    private Sub Winsock2_ConnectionRequest(byval requestID as Long)

    Winsock2.Close
    Winsock2.Accept requestID

    End Sub

    private Sub Winsock2_DataArrival(byval bytesTotal as Long)

    Dim myStream as ADODB.Stream
    Dim rst as ADODB.Recordset
    Dim strArr() as Byte

    ' get the data from socket
    Winsock2.GetData strArr()

    ' write the array to a stream
    set myStream = new ADODB.Stream
    myStream.Type = adTypeBinary
    myStream.Open
    myStream.Write strArr
    myStream.Position = 0

    ' open the strream in a recordset
    set rst = new ADODB.Recordset
    rst.Open myStream

    ' loop through recordset
    Dim msg as string
    Do Until rst.EOF
    msg = msg & rst(0) & " - " & rst(1) & " - " & rst(2) & vbCrLf
    rst.MoveNext
    Loop

    ' show content of recordset
    MsgBox msg

    End Sub




    Tom Cannaerts
    [email protected]

    Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook
    Tom Cannaerts
    email: [email protected]
    www.tom.be (dutch site)

  3. #3
    Join Date
    Jul 2001
    Location
    maharashtra,india
    Posts
    181

    Re: client/server

    thanx thanx a lot
    now i can start my project
    if i have further problems i will give trouble once more
    bye


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