Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. sockets

sockets

Scheduled Pinned Locked Moved C / C++ / MFC
databasesysadmin
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    Ni m
    wrote on last edited by
    #1

    something wrong with my func(I marked probkem arrea) : char buf[MAXCODE]; ClearString(buf); //Send "BEGINRECV" if(!send(Client,"BRCV",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf); //Send "SIZE" if (!send(Client,"SIZE",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf); char *recvSize; recvSize = new char[MAXMESS]; ClearString(recvSize); //Recieve SIZE if(!recv(Client,recvSize,4,0)) return ERR; if(!send(Client,"SUCC",MAXCODE,0)) return NOREQUEST; int size = StringToInt(recvSize); delete [] recvSize; char *data; data = new char[size]; ClearString(data); // Here recv recieves "BRCV" whatever server sends. If server doesnot send anything it anyway recieves "BRCV" // It always recieves "BRCV" if(!recv(Client,data,size,0)) return ERR; if(!send(Client,"SUCC",MAXCODE,0)) return NOREQUEST; fData.Empty(); fData = data; fData.Insert(size, '\0'); delete [] data; //Send "ENDRECV" if(!send(Client,"ERCV",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf);

    T 1 Reply Last reply
    0
    • N Ni m

      something wrong with my func(I marked probkem arrea) : char buf[MAXCODE]; ClearString(buf); //Send "BEGINRECV" if(!send(Client,"BRCV",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf); //Send "SIZE" if (!send(Client,"SIZE",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf); char *recvSize; recvSize = new char[MAXMESS]; ClearString(recvSize); //Recieve SIZE if(!recv(Client,recvSize,4,0)) return ERR; if(!send(Client,"SUCC",MAXCODE,0)) return NOREQUEST; int size = StringToInt(recvSize); delete [] recvSize; char *data; data = new char[size]; ClearString(data); // Here recv recieves "BRCV" whatever server sends. If server doesnot send anything it anyway recieves "BRCV" // It always recieves "BRCV" if(!recv(Client,data,size,0)) return ERR; if(!send(Client,"SUCC",MAXCODE,0)) return NOREQUEST; fData.Empty(); fData = data; fData.Insert(size, '\0'); delete [] data; //Send "ENDRECV" if(!send(Client,"ERCV",MAXCODE,0)) return ERR; //Request query if(!recv(Client,buf,MAXCODE,0)) return ERR; if (strnicmp(buf,"SUCC",4) != 0) return NOREQUEST; ClearString(buf);

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      have you ever tried to send a string that was containing white spaces...? the string is not sent entierly. if you do this :

      strcpy(strBuf, "hello world!");
      send(sockfd, strBuf, strlen(strBuf), 0);

      you will have "hello" received, then at the next recv() call on the peer, "world!" will be get. it looks the same thing here. are you sure you don't send a white spaced string ?


      TOXCCT >>> GEII power

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups