Thread: Connecting to Server

  1. #46
    Registered User
    Join Date
    May 2004
    Posts
    215
    I have two ws_putlines..i have that one, and then putline2

  2. #47
    Registered User
    Join Date
    May 2004
    Posts
    215
    the error is happening when it is trying to send the byte ordering to the server. i just emailed one of my co-workers she said since the server is in unix, the windows one either doesnt have it, or is different from the one on unix. i dont know how to convert the byte ordering the way its suppose to be.

    this is what my co-worker said:
    Interesting...

    So there are two kinds of byte orders that I know of "little endian" and
    "big endian". The difference is in how they order their bytes. For
    example, 2 could be 00000010 or 01000000. The stp server tries to check
    which order your using so that if it's not the same, it can swap the bytes
    for you where necessary. Here's a code snippet from the server:
    Code:
                    /* Receive the sample '2', to get the byte-order of the
    client */
                    two= 0;
                    fread(&two,1,4,fdr);
                    if(two == 2)    byteswap= 0;   /* same order */
                     else
                       {
                            if(two == 0x02000000 ) byteswap =1; /*reverse
    order */
                             else
                               {
      if(two == 0x02000000 ) byteswap =1; /*reverse
    order */
                             else
                               {
                                    puterror("unknown byte-order on client -
    cannot function - exit\n");
                                    exit(-1);
                               }
                       }
    So either windows has neither of those byte orders, or perhaps you are
    neglecting to send the number 2 through to the server.

    The unix client does this here:

    Code:
            /* send a binary sample so the server can establish byte order */
              two= 2;
              ws_putdata(&two,4);
              fflush(ws_fdw);

  3. #48
    Registered User
    Join Date
    May 2004
    Posts
    215
    sorry, u were right, it worked, thanks a lot!

  4. #49
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    [edit]
    Posted while you were posting.
    [/edit]

    Argh!

    >> I have two ws_putlines..i have that one, and then putline2<<

    There is no putline2 in the code you posted. Either way you are using ws_putline():
    Code:
               strcpy(line, "STP stpisgreat 1.4 stpc\n");
                   ws_putline(line);
    and it is wrong!

    >> So either windows has neither of those byte orders, or perhaps you are
    neglecting to send the number 2 through to the server. <<
    No what is happening, which I've been pointing out repeatedly, is that you send the authorization line twice because of your version of ws_putline(). This means, that when the server comes to read the two, it is getting instead the second copy of the authorization line.

    If you replace your ws_putline and delete the declaration line it will make things a lot easier.

  5. #50
    Registered User
    Join Date
    May 2004
    Posts
    215
    Yeah, i did that, you were right, i had two ws_putdata(), and i changed the code, and it worked. I have a question, I mean everything works, but why did I have to use raw socket functions instead of doing it the way unix did it?

  6. #51
    Registered User
    Join Date
    May 2004
    Posts
    215
    i changed the code of the ws_putline that is, not the putdata

  7. #52
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Are you sure it is working? In the code you posted you are still using fread() at about 455 and ws_getline2() at about 495. Both of these are likely to fail.

    >> I mean everything works, but why did I have to use raw socket functions instead of doing it the way unix did it? <<

    In unix a socket handle is a normal file descriptor which you can pass to fdopen(). In windows a socket is not a C file descriptor and you can not pass it to fdopen. You are meant to be able to pass the socket to _open_osfhandle() to get a C file descriptor but it doesn't seem to work.

  8. #53
    Registered User
    Join Date
    May 2004
    Posts
    215
    yeah its working, u can try it if you want, i posted it up, everything is working great, im not using ws_getline2() anymore. i took it out

  9. #54
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    That's great!

  10. #55
    Registered User
    Join Date
    May 2004
    Posts
    215
    Thanks a lot, I owe you one...or maybe 10, or 100. I dont know, but thanks a lot, i didnt really know much about networking, they just had me doing this for my internship, so im learning as we speak. So thanks a lot, im going to try to read through the code to try to understand it better. Would it be a problem if i were to ask you a question about some of the stuff we went over some other time in a message or something?

  11. #56
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    Many people suggest Beej as a good guide to network programming. Unfortunately, some of it is unix specific but it is worth a read.

    >> Would it be a problem if i were to ask you a question about some of the stuff we went over some other time in a message or something? <<
    No problems.

  12. #57
    Registered User
    Join Date
    May 2004
    Posts
    215
    Thanks a lot. :-)

  13. #58
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    >>unknown byte order format
    Any reason you're not using ntohl() and htonl() etc?

    Also, there's some good examples of read functions here:
    http://cboard.cprogramming.com/showt...333#post321434
    Adapt them to suit if you want.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  14. #59
    Registered User
    Join Date
    May 2004
    Posts
    215
    thanks hammer

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. access violation when connecting to server
    By happyclown in forum Networking/Device Communication
    Replies: 1
    Last Post: 03-10-2009, 12:46 AM
  2. connecting to server with wrong port
    By liri in forum Networking/Device Communication
    Replies: 3
    Last Post: 11-13-2007, 03:52 AM
  3. socket question
    By Unregistered in forum C Programming
    Replies: 3
    Last Post: 07-19-2002, 01:54 PM