The client program is given below, the client is relatively complex, you need to log in to the server, wait for the server to verify, if verified, enter the task message accepting status: login: unit2.cpp // -------------------------------------------------- -----------------------
#include
#include "unit2.h" #include "msg.h" #include
/ / -------------------------------------------------------------------------------------------- --------------------------- # pragma package (smart_init) #pragma resource "* .dfm" Tloginform * loginform; string username; String ServerIP ; String misur; int port; // ----------------------------------------------------------------------- ----------------------------------__ fastcall tloginform :: Tloginform (TComponent * Owner): TFORM (Owner) { ISPASS = false;} // ----------------------------------------- -------------------------------- Void __fastcall tloginform :: button1click (TOBJECT * Sender) {
IF (editname-> text.trim (). Length ()> = 30) {Application-> MessageBox ("Username is too long, please re-enter.", null, mb_ok);} else if (editpwd-> text. Trim (). Length ()> = 20) {Application-> MessageBox ("password too long, re-enter.", NULL, MB_OK;} else if (inet_addr (editserver-> text.c_str ()) = = 0xfffffffff) {Application-> MessageBox ("IP address setting is wrong, please reset.", Null, mb_ok;
} Else {clientsocket1-> Active = false; clientsocket1-> host = editserver-> text; clientsocket1-> port = port; clientsocket1-> active = true;
} // ----------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------
void __fastcall TLoginForm :: ClientSocket1Error (TObject * Sender, TCustomWinSocket * Socket, TErrorEvent ErrorEvent, int & ErrorCode) {Application-> MessageBox ( "Can not connect to the server, make sure the server program is turned on.", NULL, MB_OK); ErrorCode = 0;} // ------------------------------------------- ------------------------------ Void __fastcall Tloginform :: ClientSocket1Connect (Tobject * Sender, Tcustomwinsocket * Socket) {username = editname > Text.trim (); serverip = editserver-> text.trim (); loginInfo * loginfo = new loginInfo; memcpy (loginfo-> userid, username.c_str (), username.length () 1); memcpy (loginfo -> PWD, editpwd-> text.trim (). c_str (), editpwd-> text.trim (). Length () 1); ClientSocket1-> Socket-> Sendbuf (Loginfo, 50);
} // ----------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------
void __fastcall TLoginForm :: ClientSocket1Read (TObject * Sender, TCustomWinSocket * Socket) {MESSAGEINFO * Msg = new MESSAGEINFO; Socket-> ReceiveBuf (Msg, 244); if (Msg-> MsgType == 0xA) {isPass = true; // Write like INI CHAR DIR [MAX_PATH]; char * tfile = "/config.ini"; // Enter the program now the program is now the number of characters :: getCurrentDirectory; // Put the present directory plus the specified file name STRCAT (DIR, TFILE); TINIFILE * INI = New Tinifile (Dir); Try {INI-> Writestring ("Clientcfg", "Server", Serverip; INI-> Writestring ("Clientcfg", "User", UserName) Delete ini;} catch (...) {Application-> MessageBoxa ("Write Profile config.ini failed!", NULL, MB_OK 16); delete ini;} close ();} if (msg-> MsgType == 0xB) {Application-> MessageBox ("User Name or Password Error!", NULL, MB_OK);}} // --------------------- -------------------------------------------------- ---- Void __fastcall tloginform :: formclose (Tclosection & Action) {ClientSocket1-> Active = False;
} // ----------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------- BOOL __FASTCALL TLOGINFORM :: Getispass () {// Todo: Add Your Source Code Here Return ISPASS; Void __fastcall tloginform :: formcreate (TOBJECT * Sender) {char dir [max_path]; // ---- Get the directory of the running program Start char * tfile = "/config.ini" ;/ 将 程序 程序 现在 现在 此Character array :: getCurrentDirectory; // Plus the current directory with the specified file name STRCAT (DIR, TFILE); // ---- Get the scripture directory end tinifile * ini = new Tinifile (DIR); TEXT = INI-> ReadString ("Clientcfg", "User", ""); EditServer-> text = ini-> ReadString ("Clientcfg", "Server", ""); port = ini- > Readinteger ("Clientcfg", "Port", 1555); Misurl = INI-> ReadString ("Clientcfg", "Misurl", "http://192.168.1.101:7001/webmis/login/logincontroller.jpf"); DELETE INI;} catch (...) {messagebox (Application-> Handle, "Read Profile config.ini failed!", "Information Tips!", MB_ok MB_ICONInformation MB_SYSTEMMODAL); DELETE INI;}} // -------------------------------------------------- -------------------------
Void __fastcall Tloginform :: EditServerDblclick (TOBJECT * Sender) {EditServer-> readonly = false; editserver-> font-> color = clblack;} // ------------------------------------ -------------------------------------------------- -------
Unit2.h // --------------------------------------------- ------------------------------
#ifndef unit2H # define unit2H // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------- # include
/ / -------------------------------------------------------------------------------------------- --------------------------- Extern package tloginform * loginform; extern string username; // User Extern string serverip; extern int port; Extern String Misurl; // -------------------------------------------------------------------------------------------------------------------------------------- ---------------------------- # Endif
After the success is successful, enter the task monitor: unit1.cpp // --------------------------------------- -------------------------------------- # include
#include "unit1.h" #include "unit2.h" #include "unit3.h" #include "msg.h"
/ / -------------------------------------------------------------------------------------------- --------------------------- # pragma package (smart_init) #pragma link "trayicon" #pragma resource "* .dfm" TForm1 * Form1 ; TLIST * msglist = new tlist; // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -----------------------------------__ fastcall tform1 :: tform1 (tcomponent * oowner): TFORM (Owner) {
isCall = false; if (serverIP.Length ()> 0) {Server = serverIP; ClientSocket1-> Host = Server; ClientSocket1-> Port = port; ClientSocket1-> Active = true; btnconnect-> Enabled = false; btndisconnect-> Enabled = true;} else {application-> tERMINATE ();
StringGrid1-> defaultColwidth = 50; stringgrid1-> colwidths [2] = 600; stringgrid1-> colwidths [3] = 100; GroupBox1-> CAPTION = UserName "task list"; stringgrid1-> cells [0] [0] = "Message ID"; stringgrid1-> Cells [1] [0] = "person in charge"; stringgrid1-> cells [2] [0] = "task name"; stringgrid1-> cells [3] [0] = "time "
} // ----------------------------------------------------------------------------------------------------------------------------------------------------- ---------------------------- void __fastcall tform1 :: n2click (TOBJECT * Sender) {Application-> Terminate ();} // -------------------------------------------------- -------------------------
Void __fastcall tform1 :: trayicon1click (TOBJECT * Sender) {
IF (iSCall == true) {iscall = false; trayicon1-> iconindex = 0;}} // --------------------------- ------------------------------------ // -------------------------------------------------- -------------------------
Void __fastcall tform1 :: Timer2Timer (TOBJECT * Sender) {
IF (iSCall == true) {trayicon1-> iconindex = (gettickcount () / 500)% 2;}
} // ----------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------
Void __fastcall tform1 :: btnconnectClick (TOBJECT * Sender) {if ("Connect to Server", "Enter Server Address:", Serverip) {IF (inet_addr (serverip.c_str ()) == 0xffffffFfFfff) {Application- > MessageBox ("IP address setting is wrong, please reset.", Null, mb_ok;} else {clientsocket1-> host = serverip; clientsocket1-> active = true; btnconnect-> enabled = false; btndisconnect-> enabled = True;}}} // ------------------------------------------- --------------------------------
Void __fastcall tform1 :: clientsocket1connect (Tobject * sender, tcustomwinsocket * socket) {statusbar1-> simpletext = "Connect to:" Server; trayicon1-> iconindex = 0;} // ----------- -------------------------------------------------- ----------------
void __fastcall TForm1 :: ClientSocket1Read (TObject * Sender, TCustomWinSocket * Socket) {// server receiving transmitted MESSAGE; MESSAGEINFO * Msg = new MESSAGEINFO; Socket-> ReceiveBuf (Msg, 244); if ((Msg-> MsgType == 0xc) && ((string) msg-> usrcode == username)) {// bool isadd = true; msglist-> add (msg); / * for (int i = 1; i <= stringgrid1-> rowcount ; i ) {if (stringgrid1-> cells [0] [i] == (string) msg-> messageid) {isadd = false;}} if (isadd == true) {iscall = true;} * /} (Msg-> msgtype == 0xD) {// once polling end // Label1-> caption = msglist-> count 1; if ((msglist-> count 1)> stringgrid1-> rowcount) iscall = true; IF ((msglist-> count 1)! = StringGrid1-> rowcount) {stringgrid1-> rowcount = 0; for (int i = 0; i ) {int Rowcount = stringgrid1-> rowcount; stringgrid1-> cells [0] [RowCount] = ((MessageInfo *) msglist-> items [i]) -> messageId; stringgrid1- > Cells [1] = ((MessageInfo *) msglist-> items [i]) -> usrcode; stringgrid1-> cells [2] [RowCount] = ((MessageInfo *) msglist-> items [i]) -> Taastname; stringgrid1-> cells [3] [RowCount] =
((MessageInfo *) msglist-> items [ITEMS [I]) -> creattime; stringgrid1-> rowcount ;}} msglist = null; msglist = new tlist; label1-> caption = "Your task:" INTOSTR (StringGrid1- > Rowcount-1);}}
/ / -------------------------------------------------------------------------------------------- ---------------------------
void __fastcall TForm1 :: ClientSocket1Disconnect (TObject * Sender, TCustomWinSocket * Socket) {btnconnect-> Enabled = true; btndisconnect-> Enabled = false; StatusBar1-> SimpleText = "Could not connect to the server!"; TrayIcon1-> IconIndex = 2 } // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -----------------------------
Void __fastcall tform1 :: btndisconnectClick (TOBJECT * Sender) {ClientSocket1-> close (); btnconnect-> enabled = true; btndisconnect-> enabled = false;
} // ----------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------
void __fastcall TForm1 :: ClientSocket1Error (TObject * Sender, TCustomWinSocket * Socket, TErrorEvent ErrorEvent, int & ErrorCode) {StatusBar1-> SimpleText = "Could not connect to:" serverIP; ErrorCode = 0; btndisconnect-> Enabled = true; btnconnect-> Enabled = false;} // ----------------------------------------- --------------------------------
/ / Judgment someone's task number TFORM1 :: STRCOUNT (String Substing, String SourceStr) {// Todo: Add Your Source Code Here Int Sp = Substing.Length (); int pos = sourceStr.pos (SUBSTING); STRING TMP ; Int CAPA = 0; While (POS> 0) {TMP = SourceStr.Substring (1, POS-1); CAPA ; SourceStr = SourceStr.Substring (POS SP, SourceStr.Length () - POS-SP 1) POS = SourceStr.pos (Substing);} Return Capa;} void __fastcall tform1 :: formclose (Tobject * Sender, Tclosection & Action) {ClientSocket1-> Close ();} // ------------ -------------------------------------------------- --------------- void __fastcall tform1 :: formclick (TOBJECT * Sender) {delete msglist;} // ----------------- -------------------------------------------------- ------------
Void __fastcall tform1 :: n3click (TOBJECT * Sender) {n3-> enabled = false; formabout-> showmodal (); n3-> enabled = true;
} // ----------------------------------------------------------------------------------------------------------------------------------------------------- ----------------------------
Void __fastcall tform1 :: image1click (TOBJECT * Sender) {shellexecute (Handle, Null, misall.c_str (), null, null, sw_shownormal);} // ---------------- -------------------------------------------------- ---------
Void __fastcall tform1 :: formst * sender {if (! trayicon1-> visible) trayicon1-> visible = true; trayicon1-> minimize ();} // ----------- -------------------------------------------------- ----------------
Unit1.h // --------------------------------------------- ------------------------------
#ifndef unit1H # Define unit1H // ------------------------------------------------------------------------------------------------------------------------------------ --------------------------------- # include
void __fastcall ClientSocket1Error (TObject * Sender, TCustomWinSocket * Socket, TErrorEvent ErrorEvent, int & ErrorCode); void __fastcall FormClose (TObject * Sender, TCloseAction & Action); void __fastcall FormClick (TObject * Sender); void __fastcall N3Click (TObject * Sender); void __fastcall Image1Click (TObject * Sender); void __fastcall FormShow (TObject * Sender); private: // User declarations bool isCall; int capa; // number of tasks String Server; public: // User declarations __fastcall TForm1 (TComponent * Owner); STRCOUNT (String Substing, String Source);}; // ------------------------------------- -------------------------------------- Extern package tform1 * form1; // ---- -------------------------------------------------- --------------------- # Endif
Then it is a About interface: unit3.cpp // ---------------------------------------- -----------------------------------
#include
#include "unit3.h" // ----------------------------------------- ---------------------------------- # Pragma package (smart_init) #pragma resource "* .dfm" TFORMABOUT * FormaBout; // ---------------------------------------------- -----------------------------__ fastcall tformat :: tFormaBout (tComponent * Owner): TFORM (OWNER) {} // - -------------------------------------------------- ----------------------- void __fastcall tformast :: Button1click (TOBJECT * Sender) {modalResult = mrok;} // -------- -------------------------------------------------- -----------------
Unit3.h // --------------------------------------------- ------------------------------
#ifndef unit3H # Define unit3H // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ --------------------------------- # include
#include
Application-> CreateForm (__ classid (TForm1), & Form1); // Application-> CreateForm (__ classid (TLoginForm), & LoginForm); Application-> CreateForm (__ classid (TFormAbout), & FormAbout); Application-> Run ();} catch (Application-> showexception;} return 0;} // ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ -------------------------------------------- Also, the client's configuration The file config.ini content is as follows: [ClientCFG] user = yinhmserver = 192.168.1.55port = 1555MisURL = http: //192.168.1.101: 7001 / webmis / login / logincontroller.jpf
The above program is compiled in BCB5. The above Dongdong one is to save yourself, and the other is to help you, and hope that the cattle criticizes. It's going to have a New Year, I wish you all a happy new year, happy and auspicious