|
-
Jan 1st, 2001, 10:26 AM
#1
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.
-
Jan 1st, 2001, 11:31 AM
#2
Lively Member
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.
-
May 9th, 2001, 11:11 AM
#3
Lively Member
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.
-
May 9th, 2001, 12:20 PM
#4
Frenzied Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|