Non-Blocking Sockets

This is a discussion on Non-Blocking Sockets within the Networking/Device Communication forums, part of the General Programming Boards category; Hey all I need some help with setting information. I receive data from client then I process it but for ...

  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 07:16 AM.
    Its Really All up to you.

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,892
    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
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,424
    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?
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,341
    > 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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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, 06: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, 10:49 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21