Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
#include <iostream> #include "afxsock.h" #include "math.h" #include<string> #include<fstream> #ifdef _DEBUG #define new DEBUG_NEW #endif #define Saddress "127.0.0.1" #define port 8080 //Same port as server CWinApp theApp; using namespace std; int _tmain(int argc, TCHAR* argv[], TCHAR* envp[]) { int nRetCode = 0; //initialize MFC and print and error on failure if (!AfxWinInit(::GetModuleHandle(NULL), NULL, GetCommandLine(), 0)) { //TODO: change error code to suit your needs _tprintf(_T("Fatal error: MFC initialization failed\n")); nRetCode = 1; } else { //TODO: code your application's behaviour here CSocket client; AfxSocketInit(NULL); //1.Create Socket client.Create(); if (client.Connect(CA2W(Saddress), port)) { cout << "Client have connected to Server!" << endl; //Receiving from server the position number int id; client.Receive((char*)&id, sizeof(id), 0); cout << "\n\nThis is client number " << id + 1 << endl << endl; char r_str[1000], s_str[1000]; //Receiving returning results from server client.Receive(r_str, 10, 0); int len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; cout << "\nServer: " << r_str; //Send command q/l/r gets_s(s_str); //Wrong command while (strcmp(s_str, "3") != 0 && strcmp(s_str, "quit") != 0 && strcmp(s_str, "login") != 0 && strcmp(s_str, "1") != 0 && strcmp(s_str, "2") != 0 && strcmp(s_str, "register") != 0) { cout << "Wrong command" << endl; cout << "Retype: "; gets_s(s_str); } // goi chieu dai chuoi char buff[10]; _itoa_s(strlen(s_str), buff, 10); client.Send(buff, 10, 0); //gui chuoi client.Send(s_str, strlen(s_str), 0); if (strcmp(s_str, "3") == 0 || strcmp(s_str, "quit") == 0) { client.Close(); return nRetCode; } else if (strcmp(s_str, "1") == 0 || strcmp(s_str, "login") == 0) { int check = 0; bool success = false; do { //username client.Receive(r_str, 10, 0); len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; cout << r_str; //Send username char username[1000]; gets_s(username); // goi chieu dai chuoi _itoa_s(strlen(username), buff, 10); client.Send(buff, 10, 0); //gui chuoi client.Send(username, strlen(username), 0); // Nhan password client.Receive(r_str, 10, 0); len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; cout << r_str; //Send password char password[1000]; gets_s(password); // goi chieu dai chuoi _itoa_s(strlen(password), buff, 10); client.Send(buff, 10, 0); //gui chuoi client.Send(password, strlen(password), 0); //nhan ket qua client.Receive(r_str, 10, 0); len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; if (strcmp(r_str, "Invalid account") == 0) { cout << r_str << endl; check++; cout << 3 - check << " chances left" << endl; } else { cout << r_str; check = 3; success = true; } } while (strcmp(r_str, "Invalid account") == 0 && check != 3); if (success) { char command[1000]; gets_s(command); _itoa_s(strlen(command), buff, 10); client.Send(buff, 10, 0); //gui chuoi client.Send(command, strlen(command), 0); } else { cout << "UNSUCCESSFULL to login" << endl; } client.Close(); return nRetCode; } else if (strcmp(s_str, "2") == 0 || strcmp(s_str, "register") == 0) { client.Receive(r_str, 10, 0); len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; cout << r_str; char username[1000]; gets_s(username); _itoa_s(strlen(username), buff, 10); client.Send(buff, 10, 0); //gui chuoi client.Send(username, strlen(username), 0); client.Receive(r_str, 10, 0); len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; cout << r_str; while (strcmp(r_str, "Invalid username\n This username has already been used\n Proceed to input another username\n") == 0) { client.Receive(r_str, 10, 0); len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; cout << r_str; char username[1000]; gets_s(username); // goi chieu dai chuoi _itoa_s(strlen(username), buff, 10); client.Send(buff, 10, 0); //gui chuoi client.Send(username, strlen(username), 0); client.Receive(r_str, 10, 0); len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; cout << r_str; } // Nhan password client.Receive(r_str, 10, 0); len = atoi(r_str); client.Receive(r_str, len, 0); r_str[len] = 0; cout << r_str; //Send password char password[1000]; gets_s(password); // goi chieu dai chuoi _itoa_s(strlen(password), buff, 10); client.Send(buff, 10, 0); //gui chuoi client.Send(password, strlen(password), 0); } } else { printf("Can not connect to server!"); } getchar(); client.Close(); } getchar(); return nRetCode; }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत