public static int ByteCount(MsgClass theClass) { int theCount = 0; switch (theClass) { case MsgClass.NOTE_OFF: case MsgClass.NOTE_ON: case MsgClass.CONTROL_CHANGE: case MsgClass.POLY_AFTERTOUCH: case MsgClass.PITCH_BEND: case MsgClass.SONG_POSITION_POINTER: theCount = 2; break; case MsgClass.PROGRAM_CHANGE: case MsgClass.CHANNEL_AFTERTOUCH: case MsgClass.SONG_SELECT: theCount = 1; break; default: break; } return(theCount); }
/// <summary> /// Send message to server using socket connection. /// </summary> /// private void SendMessage(MsgClass claseprueba) { if (socketConnection == null) { return; } try { // Get a stream object for writing. NetworkStream stream = socketConnection.GetStream(); if (stream.CanWrite) { /* Esta wea es la original * string clientMessage = "This is a message from one of your clients."; */ string json = JsonUtility.ToJson(claseprueba); // Convert string message to byte array. byte[] clientMessageAsByteArray = Encoding.ASCII.GetBytes(json); // Write byte array to socketConnection stream. // Debug.Log("Client tryed to send msg"); //Debug.Log(json); stream.Write(clientMessageAsByteArray, 0, clientMessageAsByteArray.Length); } } catch (SocketException socketException) { Debug.Log("Socket exception: " + socketException); } }
/// <summary> /// Send message to client using socket connection. /// </summary> private void SendMessage(MsgClass claseprueba) { if (connectedTcpClient == null) { return; } try { // Get a stream object for writing. NetworkStream stream = connectedTcpClient.GetStream(); if (stream.CanWrite) { string json = JsonUtility.ToJson(claseprueba); // Convert string message to byte array. byte[] serverMessageAsByteArray = Encoding.ASCII.GetBytes(json); // Write byte array to socketConnection stream. stream.Write(serverMessageAsByteArray, 0, serverMessageAsByteArray.Length); //Debug.Log("Server sent his message - should be received by client"); } } catch (SocketException socketException) { Debug.Log("Socket exception: " + socketException); } }
public double GetProbabilityOf(MsgClass msgClass, string givenWord) { if (!HasProbability(givenWord)) { throw new ArgumentException("Word not found"); } return(GetProbabilityOf(givenWord, msgClass) * GetProbabilityOf(msgClass) / GetProbabilityOf(givenWord)); }
public IActionResult Check() { MsgClass mc = new MsgClass(); string view; if (Request.Form["id"].ToString().Length == 0) { mc.Msg = "type in your id"; } else if (Request.Form["pass"].ToString().Length == 0) { mc.Msg = "type in your pass"; } else if ((Regex.IsMatch(Request.Form["id"].ToString(), "[0-9]{5}")) == false) { mc.Msg = "invalid pass"; } if (mc.Msg == null) { view = "Start"; User user = new User(); LoginDao ld = new LoginDao(int.Parse(Request.Form["id"].ToString()), Request.Form["pass"].ToString()); switch (ld.DoCheck(user)) { case 1: mc.Msg = "your id does not exist"; break; case 2: mc.Msg = "your pass is incorrect"; break; case 3: mc.Msg = "system exception occurred"; break; default: mc.Msg = "login successful"; ConvertObjToArray <User> cvtObjToArr = new ConvertObjToArray <User>(); HttpContext.Session.Set("user", cvtObjToArr.DoConvert(user)); ViewData["user"] = user; break; } } else { view = "Login"; } ViewData["msg"] = mc; return(View(view)); }
/*IEnumerator SendMssgs() * { * yield return new WaitForSeconds(0.05f); * SendMssgToBoss(new MsgClass(transform.position, EndCannon.position, transform.rotation, false)); * StartCoroutine(SendMssgs()); * }*/ void SendMssgToBoss(MsgClass _msg) { if (isServer) { myServer.trySendingMsg(_msg); } else { myClient.trySendingMsg(_msg); } }
public double GetProbabilityOf(string word, MsgClass givenMsgClass) { if (!HasProbability(word)) { throw new ArgumentException("Word not found"); } return(givenMsgClass == MsgClass.Spam ? spamCountWithWord[word] / (double)totalSpamCount : hamCountWithWord[word] / (double)totalHamCount); }
public MidiMessage(byte status) { Status = status; Data1 = 0x0; Data2 = 0x0; isSet1 = false; isSet2 = false; //Set the Channel channel = CalculateChannel(status); messageClass = CalculateMessageClass(status); }
public ActionResult EmailBaseTest(string TestEmail) { if (IsPostMvc) try { DealMvc.SendMessage.Message.SendEmail("测试标题", "测试内容", TestEmail.ToString2()); MsgClass.AlertMsg(this, "邮箱信息已发送,请注意查看", true); } catch (Exception ex) { ExceptionEx.MyExceptionLog.WriteLog(this, ex); } return RedirectToAction("EmailBase"); }
/// <summary> /// Runs in background TcpServerThread; Handles incomming TcpClient requests /// </summary> private void ListenForIncommingRequests() { try { // Create listener on localhost port 8052. //tcpListener = new TcpListener(IPAddress.Parse("192.168.1.82"), 82); // este es el bueno de las pruebas con el router del profe tcpListener = new TcpListener(IPAddress.Parse(IP), Puerto); tcpListener.Start(); Debug.Log("Server is listening"); Byte[] bytes = new Byte[1024]; //bool received = false; while (abierto) { using (connectedTcpClient = tcpListener.AcceptTcpClient()) { // Get a stream object for reading using (NetworkStream stream = connectedTcpClient.GetStream()) { int length; // Read incomming stream into byte arrary. while ((length = stream.Read(bytes, 0, bytes.Length)) != 0) { var incommingData = new byte[length]; Array.Copy(bytes, 0, incommingData, 0, length); // Convert byte array to string message. string clientMessage = Encoding.ASCII.GetString(incommingData); Debug.Log("client message received as: " + clientMessage); try { MsgClass clasePrueba = JsonUtility.FromJson <MsgClass>(clientMessage); mensajeMasNuevo = clasePrueba; } catch (Exception ex) { } } } } } } catch (SocketException socketException) { Debug.Log("SocketException " + socketException.ToString()); } }
// Update is called once per frame void Update() { MyTank.position = IAPos; EndCannon.position = IAShootPos; MyTank.rotation = IARot; if (IAdidshoot) { tank.Shoot(); IAdidshoot = false; //mensajeMasNuevo = null; mensajeMasNuevo = new MsgClass(IAPos, IAShootPos, IARot, IAdidshoot, IAlive); } if (!IAlive) { tank.gameObject.SetActive(false); //mensajeMasNuevo = null; mensajeMasNuevo = new MsgClass(IAPos, IAShootPos, IARot, IAdidshoot, IAlive); } }
public IActionResult Index(int id) { ConvertArrayToObj <Regist> cato = new ConvertArrayToObj <Regist>(); byte[] array = HttpContext.Session.Get("regist"); Regist rg = cato.DoConvert(array); MsgClass mc = new MsgClass(); if (id == 1) { InsDao idao = new InsDao(); if (idao.DoInsert(rg) == 0) { mc.Msg = "new registration is done"; } } ViewData["msg"] = mc; return(View()); }
/// <summary> /// Runs in background clientReceiveThread; Listens for incomming data. /// </summary> private void ListenForData() { try { //socketConnection = new TcpClient("192.168.1.85", 8000);//jojo te voy a socketConnection = new TcpClient(IP, Puerto); Byte[] bytes = new Byte[1024]; while (abierto) { // Get a stream object for reading using (NetworkStream stream = socketConnection.GetStream()) { int length; // Read incomming stream into byte arrary. while ((length = stream.Read(bytes, 0, bytes.Length)) != 0) { var incommingData = new byte[length]; Array.Copy(bytes, 0, incommingData, 0, length); // Convert byte array to string message. string serverMessage = Encoding.ASCII.GetString(incommingData); Debug.Log("del server llego " + serverMessage); try { MsgClass clasePrueba = JsonUtility.FromJson <MsgClass>(serverMessage); mensajeMasNuevo = clasePrueba; }catch (Exception ex) { } //mensajesEnCola.Enqueue(clasePrueba); } } } } catch (SocketException socketException) { Debug.Log("Socket exception: " + socketException); } }
public double GetProbabilityOf(MsgClass msgClass) { return(msgClass == MsgClass.Spam ? 0.47 : 1 - 0.47); }
public void trySendingMsg(MsgClass msg) { SendMessage(msg); }
public static void Main () { const int numcon = 2; const int numvar = 2; // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; mosek.boundkey[] bkc = { mosek.boundkey.up, mosek.boundkey.lo }; double[] blc = { -infinity, -4.0 }; double[] buc = { 250.0, infinity }; mosek.boundkey[] bkx = { mosek.boundkey.lo, mosek.boundkey.lo }; double[] blx = { 0.0, 0.0 }; double[] bux = { infinity, infinity }; double[] c = {1.0, 0.64 }; int[][] asub = { new int[] {0, 1}, new int[] {0, 1} }; double[][] aval = { new double[] {50.0, 3.0},new double[] {31.0, -2.0} }; double[] xx = new double[numvar]; mosek.Env env = null; mosek.Task task = null; try { // Make mosek environment. env = new mosek.Env (); // Create a task object linked with the environment env. task = new mosek.Task (env, numcon,numvar); // Directs the log task stream to the user specified // method task_msg_obj.streamCB MsgClass task_msg_obj = new MsgClass (); task.set_Stream (mosek.streamtype.log,task_msg_obj); /* Give MOSEK an estimate of the size of the input data. This is done to increase the speed of inputting data. However, it is optional. */ /* Append 'numcon' empty constraints. The constraints will initially have no bounds. */ task.appendcons(numcon); /* Append 'numvar' variables. The variables will initially be fixed at zero (x=0). */ task.appendvars(numvar); /* Optionally add a constant term to the objective. */ task.putcfix(0.0); for(int j=0; j<numvar; ++j) { /* Set the linear term c_j in the objective.*/ task.putcj(j,c[j]); /* Set the bounds on variable j. blx[j] <= x_j <= bux[j] */ task.putvarbound(j,bkx[j],blx[j],bux[j]); /* Input column j of A */ task.putacol(j, /* Variable (column) index.*/ asub[j], /* Row index of non-zeros in column j.*/ aval[j]); /* Non-zero Values of column j. */ } /* Set the bounds on constraints. for i=1, ...,numcon : blc[i] <= constraint i <= buc[i] */ for(int i=0; i<numcon; ++i) task.putconbound(i,bkc[i],blc[i],buc[i]); /* Specify integer variables. */ for(int j=0; j<numvar; ++j) task.putvartype(j,mosek.variabletype.type_int); task.putobjsense(mosek.objsense.maximize); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; /* Get status information about the solution */ task.getsolsta(mosek.soltype.itg, out solsta); task.getxx(mosek.soltype.itg, // Integer solution. xx); switch(solsta) { case mosek.solsta.optimal: case mosek.solsta.near_optimal: Console.WriteLine ("Optimal primal solution\n"); for(int j = 0; j < numvar; ++j) Console.WriteLine ("x[{0}]:",xx[j]); break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: mosek.prosta prosta; task.getprosta(mosek.soltype.itg,out prosta); switch(prosta) { case mosek.prosta.prim_infeas_or_unbounded: Console.WriteLine("Problem status Infeasible or unbounded"); break; case mosek.prosta.prim_infeas: Console.WriteLine("Problem status Infeasible."); break; case mosek.prosta.unknown: Console.WriteLine("Problem status unknown."); break; default: Console.WriteLine("Other problem status."); break; } break; default: Console.WriteLine("Other solution status"); break; } } catch (mosek.Exception e) { Console.WriteLine (e.Code); Console.WriteLine (e); throw; } finally { if (task != null) task.Dispose (); if (env != null) env.Dispose (); } }
public static void Main() { const int numcon = 2; const int numvar = 2; // Since the value infinity is never used, we define // 'infinity' symbolic purposes only double infinity = 0; mosek.boundkey[] bkc = { mosek.boundkey.up, mosek.boundkey.lo }; double[] blc = { -infinity, -4.0 }; double[] buc = { 250.0, infinity }; mosek.boundkey[] bkx = { mosek.boundkey.lo, mosek.boundkey.lo }; double[] blx = { 0.0, 0.0 }; double[] bux = { infinity, infinity }; double[] c = { 1.0, 0.64 }; int[][] asub = { new int[] { 0, 1 }, new int[] { 0, 1 } }; double[][] aval = { new double[] { 50.0, 3.0 }, new double[] { 31.0, -2.0 } }; double[] xx = new double[numvar]; mosek.Env env = null; mosek.Task task = null; try { // Make mosek environment. env = new mosek.Env(); // Create a task object linked with the environment env. task = new mosek.Task(env, numcon, numvar); // Directs the log task stream to the user specified // method task_msg_obj.streamCB MsgClass task_msg_obj = new MsgClass(); task.set_Stream(mosek.streamtype.log, task_msg_obj); /* Give MOSEK an estimate of the size of the input data. * This is done to increase the speed of inputting data. * However, it is optional. */ /* Append 'numcon' empty constraints. * The constraints will initially have no bounds. */ task.appendcons(numcon); /* Append 'numvar' variables. * The variables will initially be fixed at zero (x=0). */ task.appendvars(numvar); /* Optionally add a constant term to the objective. */ task.putcfix(0.0); for (int j = 0; j < numvar; ++j) { /* Set the linear term c_j in the objective.*/ task.putcj(j, c[j]); /* Set the bounds on variable j. * blx[j] <= x_j <= bux[j] */ task.putvarbound(j, bkx[j], blx[j], bux[j]); /* Input column j of A */ task.putacol(j, /* Variable (column) index.*/ asub[j], /* Row index of non-zeros in column j.*/ aval[j]); /* Non-zero Values of column j. */ } /* Set the bounds on constraints. * for i=1, ...,numcon : blc[i] <= constraint i <= buc[i] */ for (int i = 0; i < numcon; ++i) { task.putconbound(i, bkc[i], blc[i], buc[i]); } /* Specify integer variables. */ for (int j = 0; j < numvar; ++j) { task.putvartype(j, mosek.variabletype.type_int); } task.putobjsense(mosek.objsense.maximize); task.optimize(); // Print a summary containing information // about the solution for debugging purposes task.solutionsummary(mosek.streamtype.msg); mosek.solsta solsta; /* Get status information about the solution */ task.getsolsta(mosek.soltype.itg, out solsta); task.getxx(mosek.soltype.itg, // Integer solution. xx); switch (solsta) { case mosek.solsta.optimal: case mosek.solsta.near_optimal: Console.WriteLine("Optimal primal solution\n"); for (int j = 0; j < numvar; ++j) { Console.WriteLine("x[{0}]:", xx[j]); } break; case mosek.solsta.dual_infeas_cer: case mosek.solsta.prim_infeas_cer: case mosek.solsta.near_dual_infeas_cer: case mosek.solsta.near_prim_infeas_cer: Console.WriteLine("Primal or dual infeasibility.\n"); break; case mosek.solsta.unknown: mosek.prosta prosta; task.getprosta(mosek.soltype.itg, out prosta); switch (prosta) { case mosek.prosta.prim_infeas_or_unbounded: Console.WriteLine("Problem status Infeasible or unbounded"); break; case mosek.prosta.prim_infeas: Console.WriteLine("Problem status Infeasible."); break; case mosek.prosta.unknown: Console.WriteLine("Problem status unknown."); break; default: Console.WriteLine("Other problem status."); break; } break; default: Console.WriteLine("Other solution status"); break; } } catch (mosek.Exception e) { Console.WriteLine(e.Code); Console.WriteLine(e); throw; } finally { if (task != null) { task.Dispose(); } if (env != null) { env.Dispose(); } } }