After a huge amount of code, the program was debugged for four days and finally got an eye off. It was not easy to receive server data packets! A sense of accomplishment arises ~
Experience process:
0. This function can receive server data packets from the beginning. You can know from the log:
Static void ondatareceived (byte [] Message)
1. The new class must inherit the communicationi class:
Public class icationicationmodule: communicationi
2. The new category needs to be registered with the communication module:
Public icationicationmodule ()
{
Socketclient. registermodule (this, Protocol. icationicationmodule );
}
3. The new class implements the onmessagereceived interface in communicationi:
Public void onmessagereceived (tstpackage PKG)
{
Streamwriter Sw = new streamwriter ("D: \ client.txt", true, system. Text. encoding. Default );
System. Text. utf8encoding con = new system. Text. utf8encoding ();
String inputstring = con. getstring (PKG. content );
Sw. Write ("\ r \ n" + inputstring );
Sw. Flush ();
Sw. Close ();
// Mainwindow mywnd = new mainwindow ();
// Mywnd. Show ();
}
4. In the public static bool registermodule () method, you need to modify the new project information as false:
If (_ modulecode = protocol. policy_module | _ modulecode = protocol. computer_info_module | _ modulecode = protocol. virus_module | _ modulecode = protocol. patch_module | _ modulecode = protocol. registration_module | _ modulecode = protocol. state_module | _ modulecode = protocol. icationicationmodule)
5. Add a new project field to the public class protocol class:
Public const int icationicationmodule = 0x7000;
6. In the public partial class hostingservice class, you need to initialize the new class:
New icationicationmodule. notificationmodule ();
----------------------- At this point, the client communication code has been basically configured, a lot of details, every point is terrible, various debugging tracking -----------------------------------
7. Change the code value of the server-side Java code package to the target new project:
Frontsocketserver. sendmessagetoclient (New tstpackage (protocol. icationicationmodule, 0, ("*** title ***:" + title + "*** content ***:" + content ). getbytes (), clients );
8. Add a new field for the server-side public class protocol () class, which corresponds to the client:
/**
* Pop-up window Module
*/
Public static final int icationicationmodule = 0x7000;
9. The public static void registermodule () function in public class centerservershorthandler extends iohandleradapter also needs to add new project information:
If (_ modulecode = protocol. patch_module | _ modulecode = protocol. policy_module | _ modulecode = protocol. computer_info_module | _ modulecode = protocol. virus_module | _ modulecode = protocol. registration_module | _ modulecode = protocol. state_module)
----------------------- At this point, the new client project can receive the server data packet, but the pop-up code prompts a reference error, continue to solve it -----------------------------------
Feeling: the predecessor of the project client code is indeed a great god, and every sentence of guidance is very thorough. The client framework and communication module are all written by him. I feel that these two points are the difficulties of the project. I have the opportunity to carefully study the logic of the WCF technology. In addition, WPF has the opportunity and needs further research. Following the great gods, I learned a lot and felt the pleasure of coding and debugging. This was the first time I encountered such a big difficulty. I used to learn a lot from the development of the network. If this method doesn't work, I just need to change it, however, this time, the Code logic is beautiful while being modified and re-developed based on other people's code.
Some people say that horizontal development projects are useless. I feel that it is indeed time-consuming, but it is always right to master one more technology. It has grown a lot and I have made persistent efforts!
Explanation of the communication module of the PC security Terminal Project