Results 1 to 12 of 12

Thread: Winsock, changing data types

  1. #1

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547

    Winsock, changing data types

    Well, i have a client and a server

    client sends binary or string data

    in the server, i have under the getdata function


    dim myData as string
    winsock1.getdata myData

    however, if the client is sending a byte... this will cause a problem?

    how can i interprit what is coming from the client before it lands in a variable?

    the purpose is to use 1 winsock control... any ideas?
    does it even matter if the incoming data is stored as a string?
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  2. #2
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    shouldn't you know whether it will be binary or ascii? you could just always accept it in byte() aray, then check if the data is suppose to be binary or not.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  3. #3
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    Think about it this way. At the most basic level, the data sent is just a load of bits, which is just a load of bytes. Winsock does not attach any sort of "data type" metadata when your data gets put on the wire - the data type thing is a purely artificial thing.

    IMO this is poor design from the winsock control, but that's another issue.

    Since VB uses BSTR as its string type, strings can have embedded nulls, so a byte array and a string can both be used for getting the data.

    Uh, anyway - receive the data in the most convenient form, you can always convert either way (though it's expensive).
    an ending

  4. #4

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Well, the reason why i asked this question is for the fact that my Client sends a picture to the server

    now, when I get the picture... its very distorted and fuzzy
    I recieve that data as a string, determine whether it is suppose to be just string data or if its binary data for the file...

    So I thought the problem was in recieving the data as string... but since it does not matter, it looks like my problem is somewhere else.

    Thanks

    PS: no i wont always konw if its ascii, since the same winsock control is used to send files AND simple chat messages and other such things, so i wont know if the user wants to use binary or ascii
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  5. #5
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by azteched
    Since VB uses BSTR as its string type, strings can have embedded nulls, so a byte array and a string can both be used for getting the data.
    Well for me when I do

    ?asc(chr(192))

    in the immediate pane, I get 0. Strings can't hold all 0 to 255. Much less than 255 characters. If you are going to work with extended ascii as well, then you use byte.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  6. #6

    Thread Starter
    Fanatic Member invitro's Avatar
    Join Date
    Jan 2000
    Location
    Outside your window
    Posts
    547
    Originally posted by BuggyProgrammer
    Well for me when I do

    ?asc(chr(192))

    in the immediate pane, I get 0. Strings can't hold all 0 to 255. Much less than 255 characters. If you are going to work with extended ascii as well, then you use byte.
    well i fixed my issue... i just used a string to pass the data and it seems to work. However, im not sure what you mean here.... extended ascii? can strings not support 255 chars?

    mind elaborating on that a bit, im curious
    ok, so... windows takes 1 minute to search for a file on my PC yet google.com takes 1 second to search the entire internet?

  7. #7
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    Originally posted by BuggyProgrammer
    Well for me when I do

    ?asc(chr(192))

    in the immediate pane, I get 0. Strings can't hold all 0 to 255. Much less than 255 characters. If you are going to work with extended ascii as well, then you use byte.
    Strings are stored in RAM - fundamentally all any data is, is lots of bits. Data types are "artificial", if you catch my drift.

    You can hold any data in a string of sufficient length, just as you can hold any data in a array of anything of sufficient length, because it's all just a load of bits stored in RAM.

    The issue of represnting characters on the screen is entirely separate; that's the issue you're bringing up.
    an ending

  8. #8
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by azteched
    Strings are stored in RAM - fundamentally all any data is, is lots of bits. Data types are "artificial", if you catch my drift.

    You can hold any data in a string of sufficient length, just as you can hold any data in a array of anything of sufficient length, because it's all just a load of bits stored in RAM.

    The issue of represnting characters on the screen is entirely separate; that's the issue you're bringing up.
    We are talking about the String datatype being able to HOLD all the characters, which is evidently not possible.

    Take a look at these two cases:
    VB Code:
    1. Dim bytes(0) As Byte
    2. Dim strings As String
    3.  
    4.     bytes(0) = 192
    5.     strings = Chr(192)
    6.  
    7. Open "C:\test.bin" For Binary As #1
    8.     Put #1, , bytes
    9. Close #1
    10.  
    11. Open "C:\another.bin" For Binary As #1
    12.     Put #1, , strings
    13. Close #1

    Looking in a Hex Editor, for bytes() we get
    C000010000
    which equals to 192

    for Strings, we get
    00
    which equals to 0

    So how would it be possible for strings to hold eveything? It isn't.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  9. #9
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by azteched
    Strings are stored in RAM - fundamentally all any data is, is lots of bits. Data types are "artificial", if you catch my drift.

    You can hold any data in a string of sufficient length, just as you can hold any data in a array of anything of sufficient length, because it's all just a load of bits stored in RAM.

    The issue of represnting characters on the screen is entirely separate; that's the issue you're bringing up.
    Oh yeh I mistyped Characters. I meant character codes, like 1 to 255.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  10. #10
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    Memory is memory. Strings are stored in memory. Byte types are stored in memory. There's no distinction at the fundamental level.
    an ending

  11. #11
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    Originally posted by azteched
    Memory is memory. Strings are stored in memory. Byte types are stored in memory. There's no distinction at the fundamental level.
    So what? I don't care if it is stored in memory or whatever. String datatypes can't hold the entire ascii table. Understand? You keep talking about something else.

    You first said
    so a byte array and a string can both be used for getting the data.
    which is false, because using a String WILL corrupt the data. You just, for some reason, started talking about memory, which really has nothing to do with the fact that the string will coruppt the data.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

  12. #12
    Fanatic Member
    Join Date
    Dec 2003
    Posts
    703
    As I haven't used VB winsock in ages, you're very likely to be right

    Your posts did give me the impression that you seemed to think that different datatypes were somehow differently stored at the physical level - if that wasn't the case then ignore.
    an ending

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