private void buttonOk_Click(object sender, EventArgs e) { try { // checking the connection /*if (socket == null) * { * textBoxServer.AppendText("Socket is not created. Trying to reconnect\n"); * ConnectToServer(); * }*/ if (socket.IsConnected() == false) { textBoxServer.AppendText("Connection lost. Trying to reconnect\n"); ConnectToServer(); } comboBox.Text = System.Text.RegularExpressions.Regex.Replace(comboBox.Text, @"\s+", " "); textBoxCommand.Clear(); // enter the date for commands 'getsmsafter' and 'getcallafter' if (comboBox.Text.Contains("getsmsafter") || comboBox.Text.Contains("getcallafter")) { FormDate frm = new FormDate(); frm.ShowDialog(); string temp = frm.l.ToString() + " "; comboBox.Text = comboBox.Text + " "; if (comboBox.Text.Contains("getsmsafter")) { comboBox.Text = comboBox.Text.Insert(12, temp); } else { comboBox.Text = comboBox.Text.Insert(13, temp); } } // a buffer for incoming data byte[] bytes = new byte[10000000]; // send command byte[] byData = Encoding.UTF8.GetBytes(comboBox.Text.ToString() + "\r\n"); socket.Send(byData); textBoxCommand.Text = "Sent command: " + comboBox.Text + "\n"; // get a response from server and parse int byteRec = socket.Receive(bytes); String receivedJson = Encoding.UTF8.GetString(bytes, 0, byteRec); if (comboBox.Text.Contains("sendsms")) { JsonSms sms = JsonConvert.DeserializeObject <JsonSms>(receivedJson); textBoxCommand.AppendText("Номер:" + sms.arg.ToString() + "\n"); textBoxCommand.AppendText("Текст сообщения: " + sms.arg2.ToString()); } else if (comboBox.Text.Contains("makecall")) { JsonCall call = JsonConvert.DeserializeObject <JsonCall>(receivedJson); textBoxServer.AppendText(call.answer.ToString()); } else if (comboBox.Text.Contains("getsmsafter") || comboBox.Text.Contains("getcallafter")) { JsonAnswer jsonAnswer = JsonConvert.DeserializeObject <JsonAnswer>(receivedJson); textBoxCommand.AppendText(jsonAnswer.answer.ToString()); } else if (comboBox.Text.Contains("addgroup")) { JsonSms jsonGroup = JsonConvert.DeserializeObject <JsonSms>(receivedJson); textBoxCommand.AppendText(jsonGroup.arg.ToString()); } else if (comboBox.Text.Contains("addcontact")) { JsonSms jsonContact = JsonConvert.DeserializeObject <JsonSms>(receivedJson); textBoxCommand.AppendText(jsonContact.arg.ToString()); } else { JsonAnswer jsonAnswer = JsonConvert.DeserializeObject <JsonAnswer>(receivedJson); textBoxCommand.AppendText(jsonAnswer.answer.ToString()); } } catch (Exception ex) { string message = ex.Message.ToString(); string caption = "Error!"; MessageBoxButtons buttons = MessageBoxButtons.OK; MessageBox.Show(message, caption, buttons); } finally { comboBox.Text = ""; } }
public void clr_test() { clrClass clr = new clrClass(); string str = "hello world!"; clr.stringShow(str); double fe = 33.33; //clr.readDouble(ret fe); //int []readInt = new int[1]; int readInt = 0; double[] readdbl = new double[1]; float[] readflt = new float[4]; float[,] read2flt = new float[2, 3]; unsafe { //fixed (int* pint = readInt) //{ // clr.readInt(pint); //} int *pInt = &readInt; clr.readInt(pInt); fixed(double *pdbl = readdbl) { clr.readDouble(pdbl); } fixed(float *pflt = readflt) { clr.readArray(pflt); } fixed(float *p2flt = read2flt) { clr.read2Array(p2flt); } } Console.WriteLine(String.Format("float:{0}, single:{1}, double:{2}", sizeof(float), sizeof(Single), sizeof(double))); Console.WriteLine(readInt); Console.WriteLine(readdbl[0]); Console.WriteLine(readflt[0]); Console.WriteLine(readflt[1]); Console.WriteLine(readflt[2]); Console.WriteLine(readflt[3]); Console.WriteLine(read2flt[0, 0]); Console.WriteLine(read2flt[0, 1]); Console.WriteLine(read2flt[0, 2]); Console.WriteLine(read2flt[1, 0]); Console.WriteLine(read2flt[1, 1]); Console.WriteLine(read2flt[1, 2]); clr.f(); clr.f(32); string str21 = "nifd:fe"; int i = str21.IndexOf(':'); i = str21.IndexOf(';'); i = 12; JsonCall cl = new JsonCall(); //Console.Write(cl.add(100, 200)); //string cstr = "{\"Result\":2, \"ResultValue\":[{\"ID\":2,\"Name\":\"鲁智深\",\"Age\":230,\"Sex\":\"男\"},{\"ID\":2,\"Name\":\"鲁智深1\",\"Age\":232,\"Sex\":\"男1\"}]}"; string cstr = createMapjson(); // lstStudent lst = JsonConvert.DeserializeObject<lstStudent>(cstr); unsafe { IntPtr intPtrStr = (IntPtr)Marshal.StringToHGlobalAnsi(cstr); sbyte *sbyteStr = (sbyte *)intPtrStr; //cl.showstr(sbyteStr); IntPtr rjson = Marshal.AllocCoTaskMem(4096); //sbyte* p = (sbyte*)pp; //cl.feedstr((sbyte *)rjson); //string str = Marshal.PtrToStringAnsi(pp); cl.getReturn(sbyteStr, (sbyte *)rjson); //反序列化 // Student two = JsonConvert.DeserializeObject<Student>(Marshal.PtrToStringAnsi(pp)); // // Console.WriteLine( // string.Format("学生信息 ID:{0},姓名:{1},年龄:{2},性别:{3}", // two.ID, two.Name, two.Age, two.Sex));//显示结果 } }