Results 1 to 4 of 4

Thread: How to send & receive user defined class objects through winsock control

  1. #1
    Guest

    Exclamation

    I am developing a small chat application. Sending and receiving string, but how can I send and received a formated data using a user defined class objects.

    I will be very much thankful if anyone of u can help me out.

  2. #2
    Lively Member
    Join Date
    Jan 2000
    Posts
    102
    you need to implement it yourself.
    for example, if you want to pass an integer,
    you can convert it to string, send it,
    and then reconvert it back to integer (this is for demonstration, yeah?).
    however,
    since you are talking about classes,
    it might be a nice idea to add to each class you define
    two methods: decode/encode.

    example:
    (forgive my incorrect syntax)
    class person
    name as string
    age as integer
    method: decode (person) returns string
    method: encode (string) returns person
    end class

    function encode returns string
    return name+"ZZ"+cstr(age)
    end function

    function decode (str) returns person
    split str on "ZZ"
    return new person (name=arrStr[0], age=arrStr[1])
    end function

    itay.


  3. #3
    Lively Member Ceri's Avatar
    Join Date
    Sep 2000
    Posts
    72

    No....

    Winsock can send any type of data, because in the end it's only binary data that gets sent. If you mean you want to send a User Defined Class - as in a UDT :-

    Public Type myType
    MyString as String * 20
    MyNum as Long
    MyBytes(255) as Byte
    End Type

    then you can use the CopyMemory API call to put the UDT into a byte array and then send the data, and then on the other side you can reverse the proccess by using the CopyMemory API call again. But you cannot use Variable Length Strings or un-dimentioned array's because when you try to get the size of the UDT it will be incorrect.

  4. #4
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177
    See the following thread.
    http://forums.vb-world.net/showthrea...threadid=71122

    There is a link to an example client/server app (CS.ZIP) that passes UDTs. The source has lots of comments explaining what is happening and some pitfalls to be aware of.

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