简体   繁体   中英

winsock2 sending and receiving

I've search forum but could not find proper answer for my problem. I'm going to make little logg-in procedure so I want send data being in edit box as login, then send data being in second edit box as password.

int ldata2 = send(Socket, buffs, len, 0);//send login via socket
//send pass via socket
int passData = send(Socket, buffPass, lenPass, 0);

Above instructions are handled by client off course. On server-side when i call recv ie this way:

int dt = recv(SocketM[i], 
                                        strings,
                                        128,
                                        0);

                        int errsock = WSAGetLastError();
                        if(errsock != WSAEWOULDBLOCK && errsock != 0)
                        {
                            std::cout << "ERR CODE " << errsock;
                            //shutdown(SocketM[Client]);
                            closesocket(SocketM[Client]);
                            break;
                        }
                        int passdt = recv(SocketM[i],
                                            passstrings,
                                            128,
                                            0);
                        std::cout << strings << std::endl;//Log and Password in the same buff :(
                        std::cout << passstrings //nothing in buffer why?

I get in value string data from buffs and data from buffPass instead of only from buffs for exaple: if in Log-in edit box was "Log" and in Pass edit box- "Pass" i get LogPass but i want seperate data from log to one string and data from pass to second. Please help me Please help me.

TCP is a byte-stream protocol. If you want to separate messages, it is up to you to do so, via separator characters, length-word prefixes, self-describing protocols like XML, type-length-value protocols, ...

NB it isn't valid to check WSAGetLastError() unless there was an error: ie in this case if recv() returned -1.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM