C # Detection of Landline Call number realization method of call bounce screen

Source: Internet
Author: User

In our program development, some industries use landline call screen, and C # as a Microsoft's important development tool, the application of a wide range of this code to implement the C # call DLL implementation call Bomb screen (in the case of a landline call display box, the box is stable and reliable, simple programming).

usingServiceDesk;usingSystem;usingSystem.Collections.Generic;usingSystem.ComponentModel;usingSystem.Data;usingSystem.Drawing;usingSystem.Linq;usingSystem.Net;usingSystem.Net.Sockets;usingSystem.Runtime.InteropServices;usingSystem.Text;usingSystem.Threading.Tasks;usingSystem.Windows.Forms;namespacewinf{ Public Partial classForm1:form {
The key is that the following 4 lines call the DLL's declaration [DllImport ("ZSCIDUDP.dll", CallingConvention = callingconvention.stdcall, CharSet = charset.ansi, EntryPoint ="Zscidinit")] Public Static extern intZscidinit (stringAUDPS_IP,intAudps_port,BOOLAissendstate);[DllImport ("ZSCIDUDP.dll", CallingConvention = callingconvention.stdcall, CharSet = charset.ansi, EntryPoint ="Zscidfree")] Public Static extern voidZscidfree (intARef); Public intLaidiancount {Get;Set; } Public intFref {Get;Set; } Public voidZsinit () {fref= Zscidinit ("127.0.0.1",9013,false);///The first parameter is the IP to be sent to the UDP listener after the call, the second parameter is the port number of the UDP listener} Public voidZsfree () {if(Fref >0) {zscidfree (fref); Fref=0; } } PublicForm1 () {InitializeComponent (); Udplisenter (); UDP listener is implemented here}Private voidForm1_Load (Objectsender, EventArgs e) {Zsinit (); } Private voidForm1_formclosing (Objectsender, FormClosingEventArgs e) {free (); } Private voidBtn_init_click (Objectsender, EventArgs e) {init (); } Private voidBtn_free_click (Objectsender, EventArgs e) {free (); } voidinit () {Try{zsinit (); Btn_free. Enabled=true; Btn_init. Enabled=false; } Catch(Exception ex) {MessageBox.Show (ex). Message,"Zscidinit Exception"); } finally{Txt_fref.appendtext ("Initialize the fref="+ Fref +"""+Environment.NewLine); } } voidFree () {Try{Txt_fref.appendtext ("before release "Fref="+ Fref +"""+Environment.NewLine); Zsfree (); Btn_free. Enabled=false; Btn_init. Enabled=true; } Catch(Exception ex) {MessageBox.Show (ex). Message,"Zscidfree Exception"); } finally{Txt_fref.appendtext ("after release "Fref="+ Fref +"""+Environment.NewLine); } } voidStatehandler (stringdata) {txt_state. AppendText (data. ToString ()+Environment.NewLine); } Private voidUdplisenter () {Task.Factory.StartNew ()= { intUpdport =9013; UdpClient Listener=NewUdpClient (Updport); Listener. Dontfragment=true; Listener. EnableBroadcast=true; IPEndPoint Remoteipendpoint=NewIPEndPoint (Ipaddress.loopback, Updport); while(true) { Try { byte[] bytes = listener. Receive (refremoteipendpoint); stringdata =System.Text.Encoding.Default.GetString (bytes); stringPhoneNumber =getnum (data); Writelog (PhoneNumber); } Catch(Exception ex) {MessageBox.Show (ex). Message); }}}, Taskcreationoptions.longrunning|taskcreationoptions.preferfairness); } stringGetnum (stringdata) { stringPhoneNumber =""; if(!string. Isnullorwhitespace (data)) {string[] STRs = data. Split (New string[] {"\ r \ n"}, Stringsplitoptions.none); foreach(stringKinchSTRs) { string[] tttmp = K.split ('='); if(Tttmp. Length >1&& tttmp[0] =="NUM") PhoneNumber= tttmp[1]; } } returnPhoneNumber; } voidWritelog (stringNumber ) { if(!string. Isnullorwhitespace (number)) {Txt_udprecieve. AppendText ("["+ laidiancount++ +"]: "+ number +" "+ DateTime.Now.ToString ("YYYY-MM-DD HH:mm:ss") +Environment.NewLine); Laidianwriter wer=NewLaidianwriter (); Wer. Push (number); } } } }

C # Detection of Landline Call number realization method of call bounce screen

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.