C # Server Source Code

Source: Internet
Author: User
Tags getstream sendmsg

Using system; <br/> using system. collections. generic; <br/> using system. text; <br/> using system. diagnostics; <br/> using system. runtime. interopservices; </P> <p> namespace consoleapplication22 <br/>{< br/> class Program <br/>{< br/> [dllimport ("ws2_32.dll")] <br/> Public static extern uint inet_addr (string ADDR); </P> <p> [dllimport ("iphlpapi. DLL ")] <br/> Public static extern int sendarp (uint DEST, int32 Host, ref int64 Mac, ref int32 length); </P> <p> static void main (string [] ARGs) <br/>{< br/> string [] signal = new string [5] {<br/> "59", <br/> "50 ", <br/> "23", <br/> "591", <br/> "720 "}; </P> <p> string [] Lock = new string [3] {<br/> "0/R/N ", <br/> "1/R/N", <br/> "2/R/N "}; </P> <p> string [] status = new string [4] {<br/> "stopped/R/N ", <br/> "init/R/N", <br/> "Ready/R/N", <br/> "eee/R/N "}; </P> <p> Random Ra = new random (); <br/> int tmp1 = Ra. next (); <br/> int tmp2 = Ra. next (); <br/> int tmp3 = Ra. next (); </P> <p> // The literal delimiter used to specify the delimiter used <br/> system. text. encoding ENC = system. text. encoding. utf8; </P> <p> string host = "192.168.6.125"; <br/> int Port = 14; </P> <p> system. net. IPaddress ipadd = <br/> system. net. DNS. resolve (host ). addresslist [0]; </P> <p> system. net. sockets. tcplistener listener = <br/> New syst Em. net. sockets. tcplistener (ipadd, Port); </P> <p> listener. start (); </P> <p> console. writeline ("port {0} has listen before starting creating a temporary snapshot. ", Port); </P> <p> // The accept limit must be reached when the accept limit is received. <br/> system. net. sockets. tcpclient TCP = listener. accepttcpclient (); </P> <p> console. writeline. "); </P> <p> // networkstream fetch <br/> system. net. sockets. networkstream NS = TCP. getstream (); </P> <p> string strmsg = signal [tmp1% 5] + lock [tmp2% 3] + status [tmp3% 4]; <br/> console. writeline (strmsg); </P> <p> // zookeeper sends zookeeper received messages directly. zookeeper received messages. <br/> system. io. memorystream MS = new system. io. memorystream (); <br/> byte [] resbytes = new byte [256]; <br/> int ressize; <br/> // zookeeper contains a trusted zookeeper <br/> ressize = NS. read (resb Ytes, 0, resbytes. length); <br/> // The number of characters in the trusted folder cannot exceed the number of characters in the folder. <br/> MS. write (resbytes, 0, ressize); <br/> string resmsg = ENC. getstring (Ms. toarray (); <br/> console. writeline (resmsg); <br/> // text column sort byte matching column sort bytes <br/> byte [] sendbytes = ENC. getbytes (strmsg); <br/> system. threading. thread. sleep (100); <br/> // too many minutes before sending messages <br/> ns. write (sendbytes, 0, sendbytes. length); </P> <p> // console. writeline ("Sleep begin"); <br/> // SY Stem. threading. thread. sleep (1000); <br/> // console. writeline ("Sleep end"); </P> <p> while (true) <br/>{< br/> try <br/> {<br/> NS = TCP. getstream (); <br/> resbytes = new byte [256]; <br/> ressize = NS. read (resbytes, 0, resbytes. length); <br/> MS = new system. io. memorystream (); <br/> MS. write (resbytes, 0, ressize); <br/> resmsg = ENC. getstring (Ms. toarray (); <br/> If (resmsg. indexof ("version")>-1) <Br/> {<br/> sendbytes = ENC. getbytes ("device-100 version 1.20 (junyun2.2010)"); <br/> ns. write (sendbytes, 0, sendbytes. length); <br/>}< br/> else if (resmsg. indexof ("restart")>-1) <br/>{< br/> sendbytes = ENC. getbytes (strmsg); <br/> ns. write (sendbytes, 0, sendbytes. length); <br/> console. writeline (strmsg); <br/>}</P> <p> // console. writeline (resmsg); <br/>}< br/> catch <br/>{< br/> break; <BR/>}< br/>}</P> <p> // DO <br/> // {<br/> /// too many rows have been created zookeeper sends zookeeper received zookeeper trusted zookeeper <br/> // system. io. memorystream MS = new system. io. memorystream (); <br/> // byte [] resbytes = new byte [256]; <br/> // int ressize; <br/> //// zookeeper contains a trusted zookeeper. <br/> // ressize = NS. read (resbytes, 0, resbytes. length ); <br/> /// read when 0 is returned when zookeeper has been interrupted when zookeeper has been disconnected <br/> // If (ressize = 0) <br/> // {<br/> // console. writeline ("too many failed attempts to cut off too many failed attempts. "); <Br/> // console. readline (); <br/> // return; <br/> //}< br/> /// the number of characters in the queue is small and small. <br/> // Ms. write (resbytes, 0, ressize); <br/> // string resmsg = ENC. getstring (Ms. toarray (); <br/> // console. writeline (resmsg); <br/> /// text column sort byte matching column sort bytes <br/> // byte [] sendbytes = ENC. getbytes (resmsg); <br/> // system. threading. thread. sleep (100); <br/> /// too many messages before sending messages <br/> // ns. write (sendbytes, 0, sendbytes. le Ngth); <br/> // Ms. close (); <br/> //} while (true ); <br/> // The trusted letter, letter, character, character, and character columns. <br/> // The letter, character, and message sending condition. <br/> // string sendmsg = resmsg. length. tostring () + "text"; <br/> /// character byte-type wildcard character <br/> // byte [] sendbytes = ENC. getbytes (sendmsg); <br/> /// receive messages when sending messages <br/> // ns. write (sendbytes, 0, sendbytes. length); <br/> // console. writeline (sendmsg); </P> <p> // TCP. close (); <br/> console. writeline ("Disconnect Upload Failed failed. "); </P> <p> // listener <br/> listener. stop (); <br/> console. writeline ("listener has already been called before. "); </P> <p> console. readline (); </P> <p >}< br/> static private bool checknetworkip (string remoteip) <br/>{< br/> uint ldest = inet_addr (remoteip); <br/> try <br/>{< br/> int64 macinfo = new int64 (); <br/> int32 Len = 6; <br/> int res = sendarp (ldest, 0, ref macinfo, ref Len); <br/> If (RES = 0) <br/>{< br/> return false; <br/>}< br/> else <br/>{< br/> return true; <br/>}< br/> catch (E Xception) <br/>{< br/> return false; <br/>}</P> <p >}< br/> static bool executebat (string strbatpath) <br/>{< br/> process pro = new process (); <br/> try <br/>{< br/> pro. startinfo. filename = strbatpath; // strbatpath implements full path <br/> pro. startinfo. createnowindow = false; <br/> pro. startinfo. useshellexecute = false; </P> <p> If (strbatpath. lastindexof ("//")! =-1) <br/>{< br/> pro. startinfo. workingdirectory = strbatpath. substring (0, strbatpath. lastindexof ("//"); <br/>}< br/> // when there are too many rows when there are rows when there is no such <br/> If (Pro. start () <br/>{< br/> If (! Pro. waitforexit (60*1000*5) <br/>{< br/> pro. kill (); <br/> return false; <br/>}< br/> else <br/>{< br/> pro. kill (); <br/> return false; <br/>}</P> <p >}< br/> catch (exception ex) <br/>{< br/> pro. kill (); <br/> // specify variable output <br/> return false; <br/>}< br/> pro. close (); <br/> return true; <br/>}< br/> static Public String rotencode (ref string inputtext) <br/>{< br/> int I; <br/> char Currentcharacter; <br/> int currentcharactercode; <br/> string encodedtext = ""; <br/> string outputtext = ""; <br/> // iterate through the length of the input parameter <br/> for (I = 0; I <inputtext. length; I ++) <br/>{< br/> int icurrentcharactercode =-1; </P> <p> // convert the current character to a char <br/> currentcharacter = system. convert. tochar (inputtext. substring (I, 1); </P> <p> currentc Haractercode = (INT) currentcharacter; </P> <p> If (currentcharactercode> = 97 & amp; currentcharactercode & amp; = 109) <br/>{< br/> icurrentcharactercode = currentcharactercode + 13-32; <br/>}< br/> else if (currentcharactercode >=110 & currentcharactercode <= 122) <br/>{< br/> icurrentcharactercode = currentcharactercode-13-32; <br/>}< br/> else if (currentcharactercode >=65 & currentcharacter Code <= 77) <br/>{< br/> icurrentcharactercode = currentcharactercode + 13 + 32; <br/>}< br/> else if (currentcharactercode >=78 & currentcharactercode <= 90) <br/>{< br/> icurrentcharactercode = currentcharactercode-13 + 32; <br/>}< br/> else if (currentcharactercode >=48 & currentcharactercode <= 52) <br/>{< br/> icurrentcharactercode = currentcharactercode + 5; <br/>}< br/> else if (Currentcharactercode >=53 & currentcharactercode <= 57) <br/>{< br/> icurrentcharactercode = currentcharactercode-5; <br/>}< br/> If (icurrentcharactercode! =-1) <br/>{< br/> encodedtext = (char) icurrentcharactercode + encodedtext; <br/> outputtext = outputtext + (char) currentcharactercode; <br/>}< br/> inputtext = outputtext; <br/> return encodedtext; <br/>}< br/>

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.