Thread: Non-Blocking Sockets

  1. #1
    Registered User
    Join Date
    May 2006
    Posts
    34

    Non-Blocking Sockets

    Hey all I need some help with setting information.

    I receive data from client then I process it but for some reason when I get their username from a string. And Set a struct variable to keep it, the server crashes heres my processing code.

    Code:
    string data =(string)SocketInfo->DataBuf.buf;
                   string check = data.substr(0, 4);
                   int loc = data.find( "@", 0 );
                   if(datanum[0][0].compare(check)==0){
                   SocketInfo->username = data.substr(4,loc-4);
                   }
    Last edited by unkownname; 12-29-2006 at 08:16 AM.
    Its Really All up to you.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    There's a separate forum for network programming.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Have you put 0 char into buffer before converting it to string?
    Why do you not check that the symbol is found?
    Why you don't check that the loc is actually >= 4?
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  4. #4
    Registered User
    Join Date
    May 2006
    Posts
    34
    chill out dude I have done that it just dosent go into the struct I get an error but when i output it using "cout" it displays the username correctly.
    Its Really All up to you.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > string data =(string)SocketInfo->DataBuf.buf;
    Let the compiler pick the right char array/pointer to string conversion, by removing the cast.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Jan 2005
    Location
    Estonia
    Posts
    131
    and I see no error checking there. what if if loc == string::npos? etc

  7. #7
    Registered User
    Join Date
    May 2006
    Posts
    34
    Actually I got this working after looking it up I dont like strings so I went to see how to change String to char and found something and got that fixed. Now for all those that were wondering why no check well heres the thing it always has one the first if checks if its the right set of data to see if it should do that and extract username. But to understand all of it would make me tell you my whole project and wy im using @ lol. But ya thanks anyway.
    Its Really All up to you.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pros and Cons of blocking versus non-blocking sockets?
    By abachler in forum Networking/Device Communication
    Replies: 4
    Last Post: 05-08-2008, 06:52 AM
  2. How to initialize a non blocking socket using only winsock library
    By *DEAD* in forum Networking/Device Communication
    Replies: 4
    Last Post: 01-18-2008, 07:03 AM
  3. program structure with select sockets
    By n3v in forum Networking/Device Communication
    Replies: 9
    Last Post: 06-03-2006, 06:34 AM
  4. Non blocking sockets
    By osal in forum Networking/Device Communication
    Replies: 3
    Last Post: 07-23-2004, 06:16 PM
  5. Starting window sockets
    By _Cl0wn_ in forum Windows Programming
    Replies: 2
    Last Post: 01-20-2003, 11:49 AM