{"id":228021,"date":"2014-07-01T23:04:03","date_gmt":"2014-07-01T19:04:03","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=228021"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=228021","title":{"rendered":"<span class=\"post_title\">\u041a\u0430\u043a \u044f \u043f\u0438\u0441\u0430\u043b \u0441\u0432\u043e\u0439 \u0447\u0430\u0442<\/span>"},"content":{"rendered":"<div class=\"content html_format\">     \t\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440!<br \/>  \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b, \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b \u0447\u0430\u0442. \u041e \u0435\u0433\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0438 \u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u0445 \u0432 \u0445\u043e\u0434\u0435 \u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>  \u0427\u0430\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 p2p.<br \/>  \u0421 \u043f\u043e\u0434\u0434\u0435\u0440\u043a\u0436\u043e\u0439:  <\/p>\n<ul>\n<li>\u041b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/li>\n<li>\u041a\u043e\u043c\u043d\u0430\u0442.<\/li>\n<li>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430\u0438 \u0444\u0430\u0439\u043b\u043e\u0432.<\/li>\n<li>\u0413\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0433\u043e \u0447\u0430\u0442\u0430.<\/li>\n<\/ul>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/767\/f07\/95a\/767f0795a486d76147e5fc9e4ddca1bb.png\"\/><\/p>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430: <a href=\"https:\/\/github.com\/Nirklav\/TCPChat\">GitHub<\/a><br \/>  <a name=\"habracut\"><\/a><br \/>  \u0418 \u0442\u0430\u043a \u2014 \u043f\u043e\u043d\u0435\u0441\u043b\u0430\u0441\u044c.<\/p>\n<hr\/>\n<p>  <\/p>\n<h4>\u041c\u043e\u0434\u0435\u043b\u044c<\/h4>\n<p>  <\/p>\n<ol>\n<li>\n<h6>\u0414\u0430\u043d\u043d\u044b\u0435 \u0438 \u0438\u0445 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f.<\/h6>\n<\/li>\n<li>\n<h6>API.<\/h6>\n<\/li>\n<li>\n<h6>\u0417\u0430\u043f\u0438\u0441\u044c \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u0432\u0443\u043a\u0430.<\/h6>\n<\/li>\n<\/ol>\n<h5>\u0414\u0430\u043d\u043d\u044b\u0435 \u0438 \u0438\u0445 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u044f.<\/h5>\n<p>  \u0412 \u043d\u0430\u0447\u0430\u043b\u0435 \u043a\u043e\u0433\u0434\u0430 \u044f \u043f\u0438\u0441\u0430\u043b \u043f\u0435\u0440\u0432\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e, \u044f \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043b \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u0443\u044e \u0432\u0435\u0440\u0441\u0438\u044e \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u0438 \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u041d\u043e, \u043f\u043e\u0447\u0435\u043c\u0443-\u0442\u043e, \u043d\u0430\u043f\u0440\u043e\u0447\u044c \u0437\u0430\u0431\u044b\u043b \u043f\u0440\u043e \u0442\u043e, \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0443\u0436\u043d\u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c. \u0418 \u0442\u0430\u043a-\u043a\u0430\u043a \u0441\u0435\u0440\u044c\u0435\u0437\u043d\u043e\u0439 \u043d\u0430\u0433\u0440\u0443\u0437\u043a\u0438 \u0447\u0430\u0442 \u043d\u0438\u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0438\u0441\u043f\u044b\u0442\u044b\u0432\u0430\u043b, \u0442\u043e \u044f \u043f\u043e\u043d\u044f\u043b \u044d\u0442\u043e \u0442\u043e\u043b\u044c\u043a\u043e \u043f\u043e\u0441\u043b\u0435 \u0432\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432 \u0447\u0430\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0444\u0430\u0439\u043b\u043e\u0432. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441\u0440\u0430\u0437\u0443 \u0432\u0441\u0435 \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043b\u043e\u0441\u044c \u0438 \u0432\u0435\u0437\u0434\u0435 \u0431\u044b\u043b\u043e \u0432\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043e \u043a\u0443\u0447\u0430 \u043b\u043e\u043a\u043e\u0432. \u0427\u0442\u043e \u0440\u0430\u0437\u0443\u043c\u0435\u0435\u0442\u0441\u044f \u043d\u0435 \u0431\u044b\u043b\u043e \u043b\u0443\u0447\u0448\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c. \u0415\u0441\u043b\u0438 \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0442\u043e\u0447\u043d\u0435\u0435, \u0442\u043e \u044d\u0442\u043e \u0431\u044b\u043b\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0447\u0443\u0442\u044c \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0430 \u0431\u0435\u0437 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438.<\/p>\n<p>  \u0421\u0435\u0439\u0447\u0430\u0441 \u0436\u0435 \u043d\u0430 \u043a\u043b\u0438\u0435\u043d\u0442\u0435 \u0438 \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0435\u0434\u0438\u043d\u044b\u0439 \u043c\u0435\u0445\u0430\u043d\u0438\u0437\u043c \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c. \u0411\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u043c\u043e\u0434\u0435\u043b\u044c. \u0414\u043e\u043b\u0436\u0435\u043d \u0441\u043a\u0430\u0437\u0430\u0442\u044c \u0447\u0442\u043e \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u044d\u0442\u043e \u043d\u0435 \u0441\u0430\u043c\u043e\u0435 \u0443\u0434\u0430\u0447\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435.<\/p>\n<p>  \u0418\u0434\u0435\u044f \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0430\u044f: \u0435\u0441\u0442\u044c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u044b\u043c \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u043c \u043f\u043e\u043b\u0435\u043c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u043c\u043e\u0434\u0435\u043b\u044c. \u0412 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u043e\u043d, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442 Monitor.Enter. \u041d\u0430 \u0441\u0430\u043c\u0443 \u043c\u043e\u0434\u0435\u043b\u044c, \u043b\u0438\u0431\u043e \u043d\u0430 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u043e\u0431\u044a\u0435\u043a\u0442 \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u0422\u0430\u043a \u0436\u0435 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 IDisposable \u0438 \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 Dispose \u043e\u043d \u044d\u0442\u0443 \u044d\u0442\u0443 \u043c\u043e\u0434\u0435\u043b\u044c \u043e\u0441\u0432\u043e\u0431\u043e\u0436\u0434\u0430\u0435\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043c\u0435\u0442\u043e\u0434 Monitor.Exit.<\/p>\n<p>  \u041e\u0431\u043e\u0431\u0449\u0435\u043d\u043d\u044b\u0439 \u043a\u043b\u0430\u0441\u0441 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0439 \u043a\u0430\u043a \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0442\u0430\u043a \u0438 \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430. \u0412 \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043c\u043e\u0434\u0435\u043b\u044c \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442\u0441\u044f \u043d\u0435 \u0432 \u0441\u0430\u043c\u043e\u043c \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442\u0435 \u0430 \u0432 \u043a\u043b\u0430\u0441\u0441\u0435 \u0435\u0433\u043e \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0435\u043c.  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">  public abstract class ModelContext&lt;TModel&gt; :     IDisposable   {     #region consts     private const int TimeOut = 10000;     #endregion      #region fields     private static object syncObject = new object();     protected TModel model;     #endregion      #region initialization     protected ModelContext(TModel initialModel)     {       if (!Monitor.TryEnter(syncObject, TimeOut))         throw new InvalidOperationException(&quot;model lock timeout&quot;);        model = initialModel;     }      public void Dispose()     {       model = default(TModel);        Monitor.Exit(syncObject);     }     #endregion   } } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435, \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0434\u0430\u043d\u043d\u044b\u043c \u0445\u043e\u0447\u0435\u0448\u044c-\u043d\u0435 \u0445\u043e\u0447\u0435\u0448\u044c \u0438\u0445 \u043d\u0443\u0436\u043d\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c, \u0438 \u0443\u0436\u0435 \u043d\u0435 \u0437\u0430\u0434\u0443\u043c\u044b\u0432\u0430\u0435\u0448\u044c\u0441\u044f \u043e \u0441\u0438\u043d\u0445\u0440\u043e\u043d\u0438\u0437\u0430\u0446\u0438\u0438. \u0413\u043b\u0430\u0432\u043d\u043e\u0435 \u043d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0442\u044c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u044e using. \u0414\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u044d\u0442\u043e \u043d\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043b\u0443\u0447\u0448\u0438\u043c \u0440\u0435\u0448\u0435\u043d\u0438\u0435\u043c \u0442.\u043a. \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0430 \u043a\u043e\u043c\u0430\u043d\u0434 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 2\u0443\u043c\u044f \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c\u0438 \u043c\u0430\u043a\u0441\u0438\u043c\u0443\u043c, \u0430 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u044e\u0442\u0441\u044f \u0432 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u2014 \u0432\u0441\u0435.<\/p>\n<p>  \u041a\u043e\u043d\u0442\u0435\u043a\u0441\u0442 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435 \u043c\u043e\u0436\u0435\u0442 \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u043e\u0434\u043d\u0430 \u0441\u0443\u0449\u043d\u043e\u0441\u0442\u044c (ServerModel \u2014 (\u043d\u0435\u043e\u0436\u0438\u0434\u0430\u043d\u043d\u043e) \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u0438 ClientModel \u2014 \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430). \u041e\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0443\u044e \u043f\u0440\u0438\u0432\u0430\u0442\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c (\u0441\u0430\u043c\u0443 \u0441\u0435\u0431\u044f), API \u0430 \u0442\u0430\u043a\u0436\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0435 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u0438 \u043f\u0438\u0440 \u2014 \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u043e\u0439 \u043c\u043e\u0434\u0435\u043b\u0438 \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u0434\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439. (API, \u043a\u043b\u0438\u0435\u043d\u0442 \u0438 \u0442.\u0434. \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u043a\u0430\u043a \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0435 \u043f\u043e\u043b\u044f). \u0422\u0430\u043a\u0436\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0441\u043a\u0430\u044f \u043c\u043e\u0434\u0435\u043b\u044c, \u0432 \u043e\u0442\u043b\u0438\u0447\u0438\u0438 \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0439, \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0435\u0449\u0435 \u0438 \u0441\u043e\u0431\u044b\u0442\u0438\u044f. \u041d\u0430 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u043d \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u0412 \u043e\u0431\u0449\u0435\u043c \u044d\u0442\u0438 \u043a\u043b\u0430\u0441\u0441\u044b \u0432\u044b\u0441\u0442\u0443\u043f\u0430\u044e\u0442 \u043a\u0430\u043a \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0435 \u0434\u043b\u044f \u0434\u043e\u0441\u0442\u0443\u043f\u0430 \u043a \u0447\u0435\u043c\u0443 \u043b\u0438\u0431\u043e.<br \/>  \u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u0430 \u043f\u0440\u0438\u0432\u0435\u0434\u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c (\u043e\u043d\u0430 \u043f\u043e\u043c\u0435\u043d\u044c\u0448\u0435). \u041e\u0431\u0440\u0430\u0442\u0438\u0442\u044c \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0441\u043b\u0435\u0434\u0443\u0435\u0442 \u043d\u0430 \u043c\u0435\u0442\u043e\u0434 Get() \u0441\u043e\u0437\u0434\u0430\u044e\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442.<\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">  public class ServerModel   {     #region static model     private static ServerModel model;      \/\/\/ &lt;summary&gt;     \/\/\/ \u0421\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 API     \/\/\/ &lt;\/summary&gt;     public static IServerAPI API { get; private set; }      \/\/\/ &lt;summary&gt;     \/\/\/ \u0421\u0435\u0440\u0432\u0435\u0440     \/\/\/ &lt;\/summary&gt;     public static AsyncServer Server { get; private set; }      \/\/\/ &lt;summary&gt;     \/\/\/ \u0418\u0441\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0441 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0446\u0438\u0435\u0439 using     \/\/\/ &lt;\/summary&gt;     \/\/\/ &lt;example&gt;using (var server = SeeverModel.Get()) { ... }&lt;\/example&gt;     \/\/\/ &lt;returns&gt;\u0412\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u0442 \u043c\u043e\u0434\u0435\u043b\u044c.&lt;\/returns&gt;     public static ServerContext Get()     {       if (Interlocked.CompareExchange(ref model, null, null) == null)         throw new ArgumentException(&quot;model do not inited yet&quot;);        return new ServerContext(model);     }     #endregion      #region consts     public const string MainRoomName = &quot;Main room&quot;;     #endregion      #region properties     public Dictionary&lt;string, Room&gt; Rooms { get; private set; }     public Dictionary&lt;string, User&gt; Users { get; private set; }     #endregion      #region constructor     public ServerModel()     {       Users = new Dictionary&lt;string, User&gt;();       Rooms = new Dictionary&lt;string, Room&gt;();        Rooms.Add(MainRoomName, new Room(null, MainRoomName));     }     #endregion      #region static methods     public static bool IsInited     {       get { return Interlocked.CompareExchange(ref model, null, null) != null; }     }      public static void Init(IServerAPI api)     {       if (Interlocked.CompareExchange(ref model, new ServerModel(), null) != null)         throw new InvalidOperationException(&quot;model already inited&quot;);        Server = new AsyncServer(&quot;ServerErrors.log&quot;);       API = api;     }      public static void Reset()     {       if (Interlocked.Exchange(ref model, null) == null)         throw new InvalidOperationException(&quot;model not yet inited&quot;);        if (Server != null)       {         Server.Dispose();         Server = null;       }        API = null;     }     #endregion   } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>API<\/h5>\n<p>  API \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043b\u043e\u0433\u0438\u043a\u0430 \u0447\u0430\u0442\u0430. \u041e\u043d\u0430 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0430\u0441\u0441 \u0445\u0440\u0430\u043d\u044f\u0449\u0438\u0439 \u0432 \u0441\u0435\u0431\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u043e\u0433\u0443\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0442\u0441\u044f \u043d\u0430 \u043d\u0430\u0448\u0435\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435, \u0438 \u043d\u0430\u0431\u043e\u0440 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 (\u041a\u043b\u0438\u0435\u043d\u0442\u0443, \u0435\u0441\u043b\u0438 \u0440\u0430\u0441\u0441\u043c\u0430\u0442\u0440\u0438\u0432\u0430\u0435\u043c \u0441\u0435\u0431\u044f \u0441\u043e \u0441\u0442\u043e\u0440\u043e\u043d\u044b \u0441\u0435\u0440\u0432\u0435\u0440\u0430. \u0414\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 \u044d\u0442\u043e \u0441\u0435\u0440\u0432\u0435\u0440 \u0438\u043b\u0438 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0438\u0440). \u0412 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u0441\u044f \u043d\u0430\u0438\u0431\u043e\u043b\u0435\u0435 \u0441\u043b\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u044b, \u043b\u0438\u0431\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0447\u0430\u0441\u0442\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u044b\u0435.<\/p>\n<p>  \u0420\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432\u0441\u044f \u044d\u0442\u0430 \u0441\u0438\u0441\u0442\u0435\u043c\u0430 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043e\u0431\u0440\u0430\u0437\u043e\u043c: \u043a\u0430\u043a \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043b\u0438\u0435\u043d\u0442 \u0438\u043b\u0438 \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 \u043f\u0430\u043a\u0435\u0442 \u0434\u0430\u043d\u043d\u044b\u0445, \u043e\u043d \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442 \u0435\u0433\u043e \u043d\u0430 \u0430\u043d\u0430\u043b\u0438\u0437 \u0432 API. (\u0423 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u044e\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f, \u0430 \u043e\u043d\u0438 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0434\u0435\u0440\u0433\u0430\u044e\u0442 \u043e\u0434\u0438\u043d \u043c\u0435\u0442\u043e\u0434 \u0443 \u0441\u0435\u0440\u0432\u0435\u0440\u0430, \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043d\u044f\u0442\u044b). API \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u0442 \u043f\u0435\u0440\u0432\u044b\u0435 \u0434\u0432\u0430 \u0431\u0430\u0439\u0442\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0438 \u0438\u0449\u0435\u0442 \u0443 \u0441\u0435\u0431\u044f \u0432 \u0441\u043b\u043e\u0432\u0430\u0440\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u0441 \u043d\u0443\u0436\u043d\u044b\u043c id, \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u0435\u0435. \u0418\u043b\u0438 \u043f\u0443\u0441\u0442\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043d\u0438\u0447\u0435\u0433\u043e \u043d\u0435 \u0434\u0435\u043b\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0433\u043e id \u043d\u0435\u0442. \u0414\u0430\u043b\u044c\u0448\u0435 \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u043d\u044b\u0439 \u043f\u0430\u043a\u0435\u0442, \u0438 id \u043f\u0440\u0438\u0441\u043b\u0430\u0432\u0448\u0435\u0433\u043e \u0435\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u0438 \u043e\u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u0422\u0430\u043a\u0436\u0435 API \u0438\u043c\u0435\u0435\u0442 \u0441\u0432\u043e\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441, \u0438\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0435\u0433\u043e \u043d\u0435 \u0431\u044b\u043b\u043e. \u041f\u043e\u044f\u0432\u0438\u043b\u0441\u044f \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u044f \u0440\u0435\u0448\u0438\u043b \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0434\u0440\u0443\u0433\u0443\u044e \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e, \u043f\u0440\u0435\u0434\u043f\u043e\u043b\u0430\u0433\u0430\u043b\u043e\u0441\u044c \u0447\u0442\u043e \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u0449\u0438\u0449\u0435\u043d\u043d\u043e\u0435 API. \u041d\u043e \u043f\u043e\u0442\u043e\u043c \u043c\u043d\u0435 \u044d\u0442\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0441\u0442\u0430\u043b\u043e \u043d\u0435 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e, \u0438 \u044f \u043d\u0435 \u043d\u0430 \u0434\u043e\u043b\u0433\u043e \u0437\u0430\u0431\u0440\u043e\u0441\u0438\u043b \u043f\u0440\u043e\u0435\u043a\u0442. \u041c\u0435\u0441\u044f\u0446\u0430 \u043d\u0430 \u0434\u0432\u0430. \u041f\u043e\u0441\u043b\u0435 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0435\u043d\u0438\u044f \u043a \u043d\u0435\u043c\u0443 \u043c\u043d\u0435 \u0443\u0436\u0435 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0432\u0441\u0435 \u044d\u0442\u043e \u0434\u0435\u043b\u0430\u0442\u044c, \u0438 \u044f \u0437\u0430\u043d\u044f\u043b\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0435\u0439 P2P.<\/p>\n<p>  \u041a\u043b\u0438\u0435\u043d\u0442, \u043a\u0441\u0442\u0430\u0442\u0438, \u0443\u043c\u0435\u0435\u0442 \u0441\u0430\u043c \u0432\u044b\u0431\u0438\u0440\u0430\u0442\u044c API, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440, \u0438 \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0432\u043e\u0433\u043e \u043d\u0435 \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043e\u043d \u043e\u0442\u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442\u0441\u044f \u043e\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0438 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0447\u0442\u043e \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u044b\u0439 API. \u042d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u2014 \u043f\u043e\u0441\u043b\u0435 \u0442\u043e\u0433\u043e \u043a\u0430\u043a \u0441\u0435\u0440\u0432\u0435\u0440 \u043f\u0440\u0438\u043d\u044f\u043b \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043e\u043d \u0441\u0440\u0430\u0437\u0443 \u0436\u0435 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u043d\u0430\u0437\u0432\u0430\u043d\u0438\u0435\u043c \u0441\u0432\u043e\u0435\u0433\u043e API, \u0430 \u043a\u043b\u0438\u0435\u043d\u0442 \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u043e\u0436\u0438\u0434\u0430\u0435\u0442 \u044d\u0442\u0443 \u0441\u0442\u0440\u043e\u043a\u0443 \u0438 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442 \u043d\u0443\u0436\u043d\u044b\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441. \u041d\u0443 \u0438\u043b\u0438 \u043d\u0435 \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u0442, \u0435\u0441\u043b\u0438 \u0442\u0430\u043a\u043e\u0439 \u043d\u0435 \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0443\u0436\u0435 \u0438\u0434\u0435\u0442 \u0430\u043f\u0438\u0448\u043d\u044b\u0439 \u0437\u0430\u043f\u0440\u043e\u0441 \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f \u043d\u0430 \u0441\u0435\u0440\u0432\u0435\u0440\u0435.<\/p>\n<p>  \u041c\u0435\u0442\u043e\u0434 \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u043e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u044e\u0449\u0435\u0433\u043e \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u0435 \u043f\u0430\u043a\u0435\u0442\u044b:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">  public class DataReceivedEventArgs : EventArgs   {     public byte[] ReceivedData { get; set; }     public Exception Error { get; set; }   }    public interface IServerAPICommand   {     void Run(ServerCommandArgs args);   }    public class ServerCommandArgs   {     public string ConnectionId { get; set; }     public byte[] Message { get; set; }   }      private void DataReceivedCallBack(object sender, DataReceivedEventArgs e)     {       try       {         if (e.Error != null)           throw e.Error;          if (!isServerRunning)           return;          IServerAPICommand command = ServerModel.API.GetCommand(e.ReceivedData);         ServerCommandArgs args = new ServerCommandArgs         {           Message = e.ReceivedData,           ConnectionId = ((ServerConnection)sender).Id,         };          command.Run(args);       }       catch (Exception exc)       {         ServerModel.Logger.Write(exc);       }     } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041f\u043e\u043b\u043d\u044b\u0439 \u043a\u043e\u0434 \u043a\u043b\u0430\u0441\u0441\u0430 API (\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u2014 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0433\u043e):  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">  \/\/\/ &lt;summary&gt;   \/\/\/ \u041a\u043b\u0430\u0441\u0441 \u0440\u0435\u0430\u0437\u0438\u0443\u044e\u0449\u0438\u0439 \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u043e\u0435 \u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0435 API.   \/\/\/ &lt;\/summary&gt;   public class StandardServerAPI : IServerAPI   {     \/\/\/ &lt;summary&gt;     \/\/\/ \u0412\u0435\u0440\u0441\u0438\u044f \u0438 \u0438\u043c\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e API.     \/\/\/ &lt;\/summary&gt;     public const string API = &quot;StandartAPI v2.0&quot;;      private Dictionary&lt;ushort, IServerAPICommand&gt; commandDictionary = new Dictionary&lt;ushort, IServerAPICommand&gt;();      \/\/\/ &lt;summary&gt;     \/\/\/ \u0421\u043e\u0437\u0434\u0430\u0435\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 API.     \/\/\/ &lt;\/summary&gt;     \/\/\/ &lt;param name=&quot;host&quot;&gt;\u0421\u0435\u0440\u0432\u0435\u0440 \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0439 API.&lt;\/param&gt;     public StandardServerAPI()     {       commandDictionary.Add(ServerRegisterCommand.Id, new ServerRegisterCommand());       commandDictionary.Add(ServerUnregisterCommand.Id, new ServerUnregisterCommand());       commandDictionary.Add(ServerSendRoomMessageCommand.Id, new ServerSendRoomMessageCommand());       commandDictionary.Add(ServerSendPrivateMessageCommand.Id, new ServerSendPrivateMessageCommand());       commandDictionary.Add(ServerGetUserOpenKeyCommand.Id, new ServerGetUserOpenKeyCommand());       commandDictionary.Add(ServerCreateRoomCommand.Id, new ServerCreateRoomCommand());       commandDictionary.Add(ServerDeleteRoomCommand.Id, new ServerDeleteRoomCommand());       commandDictionary.Add(ServerInviteUsersCommand.Id, new ServerInviteUsersCommand());       commandDictionary.Add(ServerKickUsersCommand.Id, new ServerKickUsersCommand());       commandDictionary.Add(ServerExitFormRoomCommand.Id, new ServerExitFormRoomCommand());       commandDictionary.Add(ServerRefreshRoomCommand.Id, new ServerRefreshRoomCommand());       commandDictionary.Add(ServerSetRoomAdminCommand.Id, new ServerSetRoomAdminCommand());       commandDictionary.Add(ServerAddFileToRoomCommand.Id, new ServerAddFileToRoomCommand());       commandDictionary.Add(ServerRemoveFileFormRoomCommand.Id, new ServerRemoveFileFormRoomCommand());       commandDictionary.Add(ServerP2PConnectRequestCommand.Id, new ServerP2PConnectRequestCommand());       commandDictionary.Add(ServerP2PReadyAcceptCommand.Id, new ServerP2PReadyAcceptCommand());       commandDictionary.Add(ServerPingRequestCommand.Id, new ServerPingRequestCommand());     }      \/\/\/ &lt;summary&gt;     \/\/\/ \u0412\u0435\u0440\u0441\u0438\u044f \u0438 \u0438\u043c\u044f \u0434\u0430\u043d\u043d\u043e\u0433\u043e API.     \/\/\/ &lt;\/summary&gt;     public string Name     {       get { return API; }     }      \/\/\/ &lt;summary&gt;     \/\/\/ \u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u0442 \u043a\u043e\u043c\u0430\u043d\u0434\u0443.     \/\/\/ &lt;\/summary&gt;     \/\/\/ &lt;param name=&quot;message&quot;&gt;\u041f\u0440\u0438\u0448\u0435\u0434\u0448\u0435\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u0442 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0430 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0434\u043b\u044f \u0438\u0437\u0432\u043b\u0435\u043a\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430.&lt;\/param&gt;     \/\/\/ &lt;returns&gt;\u041a\u043e\u043c\u0430\u043d\u0434\u0430 \u0434\u043b\u044f \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f.&lt;\/returns&gt;     public IServerAPICommand GetCommand(byte[] message)     {       ushort id = BitConverter.ToUInt16(message, 0);        IServerAPICommand command;       if (commandDictionary.TryGetValue(id, out command))         return command;        return ServerEmptyCommand.Empty;     }      \/\/\/ &lt;summary&gt;     \/\/\/ \u041d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0441\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u0442 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439.     \/\/\/ &lt;\/summary&gt;     \/\/\/ &lt;param name=&quot;container&quot;&gt;&lt;\/param&gt;     public void IntroduceConnections(string senderId, IPEndPoint senderPoint, string requestId, IPEndPoint requestPoint)     {       using (var context = ServerModel.Get())       {         var content = new ClientWaitPeerConnectionCommand.MessageContent         {           RequestPoint = requestPoint,           SenderPoint = senderPoint,           RemoteInfo = context.Users[senderId],         };          ServerModel.Server.SendMessage(requestId, ClientWaitPeerConnectionCommand.Id, content);       }     }      \/\/\/ &lt;summary&gt;     \/\/\/ \u041f\u043e\u0441\u044b\u043b\u0430\u0435\u0442 \u0441\u0438\u0441\u0442\u0435\u043c\u043d\u043e\u0435 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u0443.     \/\/\/ &lt;\/summary&gt;     \/\/\/ &lt;param name=&quot;nick&quot;&gt;\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u043f\u043e\u043b\u0443\u0447\u0430\u0449\u0438\u0439 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.&lt;\/param&gt;     \/\/\/ &lt;param name=&quot;message&quot;&gt;\u0421\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435.&lt;\/param&gt;     public void SendSystemMessage(string nick, string message)     {       var sendingContent = new ClientOutSystemMessageCommand.MessageContent { Message = message };       ServerModel.Server.SendMessage(nick, ClientOutSystemMessageCommand.Id, sendingContent);     }      \/\/\/ &lt;summary&gt;     \/\/\/ \u0417\u0430\u043a\u0440\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435.     \/\/\/ &lt;\/summary&gt;     \/\/\/ &lt;param name=&quot;nick&quot;&gt;\u041d\u0438\u043a \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f, \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043a\u043e\u0442\u0440\u043e\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u0437\u0430\u043a\u0440\u044b\u0442\u043e.&lt;\/param&gt;     public void CloseConnection(string nick)     {       ServerModel.Server.CloseConnection(nick);        using (var server = ServerModel.Get())       {         foreach (string roomName in server.Rooms.Keys)         {           Room room = server.Rooms[roomName];            if (!room.Users.Contains(nick))             continue;            room.Remove(nick);           server.Users.Remove(nick);            var sendingContent = new ClientRoomRefreshedCommand.MessageContent           {             Room = room,             Users = room.Users.Select(n =&gt; server.Users[n]).ToList()           };            foreach (string user in room.Users)           {             if (user == null)               continue;              ServerModel.Server.SendMessage(user, ClientRoomRefreshedCommand.Id, sendingContent);           }         }       }     }   } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<p>  \u041a\u0430\u0436\u0434\u0430\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0440\u0435\u0430\u043b\u0438\u0437\u0443\u0435\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441 \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u0414\u043b\u044f \u0441\u0435\u0440\u0432\u0435\u0440\u0430 IServerAPICommand, \u0434\u043b\u044f \u043a\u043b\u0438\u0435\u043d\u0442\u0430 IClientAPICommand, \u043d\u0430 \u0434\u0430\u043d\u043d\u043e\u043c \u044d\u0442\u0430\u043f\u0435 \u0438\u0445 \u043c\u043e\u0436\u043d\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u0441\u0432\u0435\u0441\u0442\u0438 \u043a 1 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0443, \u043d\u043e \u043c\u043d\u0435 \u044d\u0442\u043e\u0433\u043e \u0434\u0435\u043b\u0430\u0442\u044c \u043f\u043e\u0447\u0435\u043c\u0443 \u0442\u043e \u043d\u0435 \u0445\u043e\u0447\u0435\u0442\u0441\u044f. \u0422\u0430\u043a\u0436\u0435 \u043e\u043d\u0430 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0441\u0432\u043e\u0439 Id \u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u044b\u0435 \u0434\u043b\u044f \u0435\u0435 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u044f, \u043e\u043f\u0438\u0441\u044b\u0432\u0430\u044e\u0449\u0435\u0435\u0441\u044f \u043a\u043b\u0430\u0441\u0441\u043e\u043c MessageContent. \u0412\u043f\u0440\u043e\u0447\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0435 \u043c\u043e\u0433\u0443\u0442 \u0431\u044b\u0442\u044c \u0438 \u043d\u0435 \u043d\u0443\u0436\u043d\u044b \u0434\u0430\u043d\u043d\u044b\u0435. \u0418 \u043e\u043d\u0430 \u0441\u0430\u043c\u0430 \u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0435\u043d\u043d\u0430 \u0437\u0430 \u0442\u043e, \u0447\u0442\u043e \u0431\u044b \u0434\u0435\u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0430\u0431\u043e\u0440 \u0431\u0430\u0439\u0442 \u0432 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u043a\u043b\u0430\u0441\u0441\u0430.<\/p>\n<p>  \u041f\u0440\u0438\u043c\u0435\u0440 \u043a\u043e\u043c\u0430\u043d\u0434\u044b. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u043a\u043e\u043c\u0430\u043d\u0434\u0430 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u044f \u0444\u0430\u0439\u043b\u0430 \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0443:  <\/p>\n<div class=\"spoiler\"><b class=\"spoiler_title\">\u041a\u043e\u0434<\/b><\/p>\n<div class=\"spoiler_text\">\n<pre><code class=\"cs\">   public interface IServerAPICommand   {     void Run(ServerCommandArgs args);   }    public class ServerCommandArgs   {     public string ConnectionId { get; set; }     public byte[] Message { get; set; }   }    abstract class BaseCommand   {     protected static T GetContentFormMessage&lt;T&gt;(byte[] message)     {       using (MemoryStream messageStream = new MemoryStream(message))       {         messageStream.Position = sizeof(ushort);         BinaryFormatter formatter = new BinaryFormatter();         T receivedContent = (T)formatter.Deserialize(messageStream);         return receivedContent;       }     }   }    class ServerAddFileToRoomCommand :       BaseServerCommand,       IServerAPICommand   {     public void Run(ServerCommandArgs args)     {       MessageContent receivedContent = GetContentFormMessage&lt;MessageContent&gt;(args.Message); \/\/\u0418\u0437\u0432\u043b\u0435\u043a\u0430\u0435\u043c \u043a\u043e\u043d\u0442\u0435\u043d\u0442.        if (receivedContent.File == null)         throw new ArgumentNullException(&quot;File&quot;);        if (string.IsNullOrEmpty(receivedContent.RoomName))         throw new ArgumentException(&quot;RoomName&quot;);        if (!RoomExists(receivedContent.RoomName, args.ConnectionId))         return;        using (var context = ServerModel.Get()) \/\/\u041f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u043e\u0441\u0442\u0443\u043f \u043a \u043c\u043e\u0434\u0435\u043b\u0438, \u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u0443\u0435\u043c \u0435\u0435       {         Room room = context.Rooms[receivedContent.RoomName];          if (!room.Users.Contains(args.ConnectionId))         {           ServerModel.API.SendSystemMessage(args.ConnectionId, &quot;\u0412\u044b \u043d\u0435 \u0432\u0445\u043e\u0434\u0438\u0442\u0435 \u0432 \u0441\u043e\u0441\u0442\u0430\u0432 \u044d\u0442\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u044b.&quot;);           return;         }          if (room.Files.FirstOrDefault(file =&gt; file.Equals(receivedContent.File)) == null)           room.Files.Add(receivedContent.File);          var sendingContent = new ClientFilePostedCommand.MessageContent         {           File = receivedContent.File,           RoomName = receivedContent.RoomName         };          \/\/\u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432\u0441\u0435\u043c \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u043c \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0435         \/\/\u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u043e \u0442\u043e\u043c \u0447\u0442\u043e \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0443 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u0444\u0430\u0439\u043b, \u043a\u0430\u043a \u0432\u044b \u0443\u0436\u0435 \u0434\u043e\u0433\u0430\u0434\u0430\u043b\u0438\u0441\u044c         foreach (string user in room.Users)           ServerModel.Server.SendMessage(user, ClientFilePostedCommand.Id, sendingContent);        }     }      [Serializable]     public class MessageContent     {       string roomName;       FileDescription file;        public string RoomName { get { return roomName; } set { roomName = value; } }       public FileDescription File { get { return file; } set { file = value; } }     }      public const ushort Id = (ushort)ServerCommand.AddFileToRoom;   } <\/code><\/pre>\n<p>  <\/div>\n<\/div>\n<h5>\u0417\u0430\u043f\u0438\u0441\u044c \u0438 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435 \u0437\u0432\u0443\u043a\u0430.<\/h5>\n<p>  \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0433\u043e \u0447\u0430\u0442\u0430 \u0437\u0430\u043d\u044f\u043b\u0441\u044f \u043d\u0435\u0434\u0430\u0432\u043d\u043e, \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u0432\u043e \u0432\u0440\u0435\u043c\u044f \u043f\u0443\u0431\u043b\u0438\u043a\u0430\u0446\u0438\u0438 \u043e\u043d \u0432\u0441\u0435 \u0435\u0449\u0435 \u0431\u0443\u0434\u0435\u0442 \u0432 \u0434\u0435\u043c\u043e \u0432\u0435\u0440\u0441\u0438\u0438. \u041d\u043e \u0443\u0436\u0435 \u0443\u0441\u043f\u0435\u043b \u043f\u043e\u0432\u043e\u0437\u0438\u0442\u0441\u044f \u0441 \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u0435\u043c \u0438 \u0437\u0430\u043f\u0438\u0441\u044c\u044e \u0437\u0432\u0443\u043a\u0430.<\/p>\n<p>  \u041f\u0435\u0440\u0432\u044b\u043c \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u043c \u0431\u044b\u043b\u0438 WinApi \u0444\u0443\u043d\u043a\u0446\u0438\u0438 waveIn* waveOut*. \u042d\u0442\u043e \u0431\u044b\u043b \u0441\u0430\u043c\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e\u0439 \u0432\u0430\u0440\u0438\u0430\u043d\u0442, \u043f\u043e\u044d\u0442\u043e\u043c\u0443 \u043d\u0430\u0447\u0430\u043b \u0441 \u043d\u0435\u0433\u043e. \u041d\u043e \u0441 \u043d\u0438\u043c\u0438 \u043d\u0435 \u0441\u043b\u043e\u0436\u0438\u043b\u043e\u0441\u044c, \u0442.\u043a. \u043d\u0430 \u0432\u0435\u0440\u0441\u0438\u0438 framework&#8217;a 3.5 \u043d\u0435\u0430\u0434\u0435\u043a\u0432\u0430\u0442\u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u043c\u0430\u0440\u0448\u0430\u043b\u0438\u043d\u0433 \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 x64 \u0438 \u043f\u0440\u0438 \u0437\u0430\u043f\u0443\u0441\u043a\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u043f\u0440\u043e\u0441\u0442\u043e \u043f\u0430\u0434\u0430\u043b\u043e \u0431\u0435\u0437 \u043a\u0430\u043a\u0438\u0445 \u043b\u0438\u0431\u043e \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u041f\u0440\u0438 \u0441\u0431\u043e\u0440\u043a\u0435 \u043f\u043e\u0434 \u044586 \u0432\u0441\u0435 \u0431\u044b\u043b\u043e \u043d\u043e\u0440\u043c\u0430\u043b\u044c\u043d\u043e.<\/p>\n<p>  \u0414\u0430\u043b\u044c\u0448\u0435 \u0431\u044b\u043b\u0430 \u043f\u043e\u043f\u044b\u0442\u043a\u0430 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u044c DirectSound, \u043d\u043e \u0443 \u043d\u0435\u0433\u043e \u0431\u044b\u043b \u043d\u0430\u0439\u0434\u0435\u043d \u0441\u0432\u043e\u0439 \u0431\u0430\u0433 \u0441 \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u043e \u0437\u0430\u0432\u0435\u0440\u0448\u0435\u043d\u0438\u0438 \u043f\u0440\u043e\u0438\u0433\u0440\u044b\u0432\u0430\u043d\u0438\u044f \u043a\u0443\u0441\u043a\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041f\u043e\u0441\u043b\u0435 \u0433\u0443\u0433\u043b\u0435\u043d\u0438\u044f \u043d\u0430 \u044d\u0442\u0443 \u0442\u0435\u043c\u0443 \u0432\u044b\u044f\u0441\u043d\u0438\u043b\u043e\u0441\u044c, \u0447\u0442\u043e Mircosoft \u0434\u0430\u0432\u043d\u043e \u0437\u0430\u0431\u0440\u043e\u0441\u0438\u043b\u0438 DirectSound \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 \u0441 XAudio2. \u041a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0435\u0433\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0435 \u043f\u0440\u0438\u0432\u0435\u043b\u043e \u0431\u044b \u043a \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043a\u043e\u043c\u043f\u0438\u043b\u044f\u0446\u0438\u0438 2\u0443\u0445 \u0432\u0435\u0440\u0441\u0438\u0439 \u044586 \u0438 \u044564.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u043d\u0435 \u043d\u0435 \u0445\u043e\u0442\u0435\u043b\u043e\u0441\u044c \u0441\u0430\u043c\u043e\u043c\u0443 \u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0443 \u0434\u043b\u044f XAudio2, \u0442\u043e \u044f \u0432\u0441\u043f\u043e\u043c\u043d\u0438\u043b \u043f\u0440\u043e OpenAL. \u0414\u043b\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0435\u0441\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0430 (OpenTK), \u0435\u0449\u0435 \u0438 \u0441 \u043e\u0442\u043a\u0440\u044b\u0442\u044b\u043c \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u043c \u043a\u043e\u0434\u043e\u043c. \u0418\u0437 OpenTK \u0431\u044b\u043b \u0430\u043a\u043a\u0443\u0440\u0430\u0442\u043d\u043e \u0432\u044b\u0440\u0435\u0437\u0430\u043d \u0442\u043e\u043b\u044c\u043a\u043e \u0441\u0430\u043c\u0430 \u0430\u0443\u0434\u0438\u043e \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430. \u041a\u043e\u0442\u043e\u0440\u0430\u044f \u0441\u0435\u0439\u0447\u0430\u0441 \u0438 \u0440\u0430\u0431\u043e\u0442\u0430\u0435\u0442 \u0432 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u0435.<\/p>\n<p>  \u0422\u0430\u043a \u043a\u0430\u043a \u043c\u043d\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c OpenGL ES 2, \u0442\u043e \u0438 \u0441 OpenAL \u044f \u043f\u043e\u0434\u0440\u0443\u0436\u0438\u043b\u0441\u044f \u0441\u0440\u0430\u0437\u0443. \u041e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0435 \u0435\u0441\u043b\u0438 \u0443\u0447\u0435\u0441\u0442\u044c \u0447\u0442\u043e \u043f\u043e \u043d\u0435\u043c\u0443 \u043d\u0430 \u043e\u0444\u0438\u0446\u0438\u0430\u043b\u044c\u043d\u043e\u043c \u0441\u0430\u0439\u0442\u0435 OpenTK \u0435\u0441\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440\u044b.<\/p>\n<p>  \u0414\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u044f \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u0443\u044e \u0441\u0445\u0435\u043c\u0443, \u0438\u0437 \u043f\u0440\u0438\u043c\u0435\u0440\u0430. \u041f\u0440\u0438 \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0438 \u0437\u0430\u043f\u0438\u0441\u0438, \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0435\u0442\u0441\u044f \u0442\u0430\u0439\u043c\u0435\u0440, \u043f\u0435\u0440\u0438\u043e\u0434 \u0441\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u0442\u043e\u0440\u043e\u0433\u043e \u043d\u0430\u0441\u0442\u0440\u0430\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043d\u0430 \u0432\u0440\u0435\u043c\u044f, \u0437\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u0431\u0443\u0444\u0435\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u0437\u0430\u043f\u043e\u043b\u043d\u0438\u0442\u0441\u044f \u043d\u0430 \u043f\u043e\u043b\u043e\u0432\u0438\u043d\u0443. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0434\u0430\u043d\u043d\u044b\u0435 \u0438\u0437 \u043d\u0435\u0433\u043e \u0441\u0447\u0438\u0442\u044b\u0432\u0430\u044e\u0442\u0441\u044f \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u043e\u0439 ClientPlayVoiceCommand \u0432\u0441\u0435\u043c \u043a\u0442\u043e \u043c\u043e\u0436\u0435\u0442 \u0441\u043b\u0443\u0448\u0430\u0442\u044c \u043d\u0430\u0441.<\/p>\n<p>  \u041a\u043e\u0434 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c \u0432 \u0432\u0435\u0442\u043a\u0435 <a href=\"https:\/\/github.com\/Nirklav\/TCPChat\/tree\/master\/Engine\/Audio\/OpenAL\">TCPChat\\Engine\\Audio\\OpenAL<\/a>.<\/p>\n<hr\/>\n<h4>\u0421\u0435\u0442\u044c<\/h4>\n<p>  \u0418\u0437\u043d\u0430\u0447\u0430\u043b\u044c\u043d\u043e \u0447\u0430\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u043b \u0441\u043e\u0431\u043e\u0439 \u043e\u0434\u043d\u0443 \u0433\u043b\u0430\u0432\u043d\u043e\u0435 \u043a\u043e\u043c\u043d\u0430\u0442\u0443, \u0433\u0434\u0435 \u043d\u0430\u0445\u043e\u0434\u0438\u043b\u0438\u0441\u044c \u0432\u0441\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0438. \u0418\u0437 \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u0432 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043b\u0441\u044f \u0442\u043e\u043b\u044c\u043a\u043e TCP. \u0422\u0430\u043a \u2014 \u043a\u0430\u043a \u043e\u043d \u0443\u0436\u0435 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0434\u0430\u043d\u043d\u044b\u0445 \u043e\u0441\u0442\u0430\u0432\u0430\u043b\u043e\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0440\u0430\u0437\u0431\u0438\u0442\u044c \u0435\u0433\u043e \u043d\u0435\u043f\u0440\u0435\u0440\u044b\u0432\u043d\u044b\u0439 \u043f\u043e\u0442\u043e\u043a \u043d\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f. <\/p>\n<p>  \u042d\u0442\u043e \u0431\u044b\u043b\u043e \u0441\u0434\u0435\u043b\u0430\u043d\u043e \u043f\u0440\u043e\u0441\u0442\u043e \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043d\u0438\u0435\u043c \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u0432 \u0435\u0433\u043e \u043d\u0430\u0447\u0430\u043b\u043e.<br \/>  \u0422\u043e \u0435\u0441\u0442\u044c \u043f\u0430\u043a\u0435\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0438\u0437 \u0441\u0435\u0431\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0435:<br \/>  \u041f\u0435\u0440\u0432\u044b\u0435 4 \u0431\u0430\u0439\u0442\u0430 \u2014 \u0440\u0430\u0437\u043c\u0435\u0440 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f.<br \/>  5-6 \u0431\u0430\u0439\u0442 \u2014 \u0438\u0434\u0435\u043d\u0442\u0438\u0444\u0438\u043a\u0430\u0442\u043e\u0440 \u043a\u043e\u043c\u0430\u043d\u0434\u044b.<br \/>  \u041e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u044d\u0442\u043e \u0441\u0435\u0440\u0438\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0439 MessageContent.<\/p>\n<p>  \u0414\u0430\u043b\u0435\u0435 \u043d\u0430 \u043e\u0434\u043d\u043e\u043c \u0444\u043e\u0440\u0443\u043c\u0435 \u043c\u043d\u0435 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0438\u043b\u0438 \u0432\u0432\u0435\u0441\u0442\u0438 \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0443 \u0444\u0430\u0439\u043b\u043e\u0432 \u0438 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u0443\u044e \u0441\u0432\u044f\u0437\u044c. \u0421 \u0444\u0430\u0439\u043b\u0430\u043c\u0438 \u044f \u0441\u043f\u0440\u0430\u0432\u0438\u043b\u0441\u044f \u043f\u043e\u0447\u0442\u0438 \u0441\u0440\u0430\u0437\u0443, \u043f\u0440\u0430\u0432\u0434\u0430 \u0432 \u043f\u0435\u0440\u0432\u043e\u0439 \u0432\u0435\u0440\u0441\u0438\u0438 \u0444\u0430\u0439\u043b\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u043b\u0438\u0441\u044c \u0447\u0435\u0440\u0435\u0437 \u0441\u0435\u0440\u0432\u0435\u0440, \u0447\u0442\u043e \u0431\u044b\u043b\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0443\u0436\u0430\u0441\u043d\u043e. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u044f \u0437\u0430\u0434\u0443\u043c\u0430\u043b\u0441\u044f \u043d\u0430\u0434 \u0442\u0435\u043c, \u0447\u0442\u043e \u0445\u043e\u0440\u043e\u0448\u043e \u0431\u044b\u043b\u043e \u0431\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0432\u0430\u0442\u044c \u0438\u0445 \u043d\u0430 \u043f\u0440\u044f\u043c\u0443\u044e. \u041a\u0430\u043a \u0432\u044b \u0437\u043d\u0430\u0435\u0442\u0435 \u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u043e\u0439 NAT, \u044d\u0442\u043e \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u043d\u0435 \u0442\u0430\u043a \u0442\u043e \u0438 \u043f\u0440\u043e\u0441\u0442\u043e.<\/p>\n<p>  \u042f \u0434\u043e\u043b\u0433\u043e \u0432\u043e\u0437\u0438\u043b\u0441\u044f \u0438 \u043f\u044b\u0442\u0430\u043b\u0441\u044f \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u043e\u0431\u0445\u043e\u0434 NAT \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f TCP, \u0442\u043e\u0433\u0434\u0430 \u0431\u044b \u043d\u0435 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043f\u0430\u0440\u0438\u0442\u0441\u044f \u043f\u043e \u043f\u043e\u0432\u043e\u0434\u0443 \u043d\u0435\u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u0438 UDP. \u0421 \u043d\u0438\u043c \u0442\u0430\u043a \u043d\u0438\u0447\u0435\u0433\u043e \u0438 \u043d\u0435 \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u043e\u0441\u044c. \u041f\u043e\u0441\u043b\u0435 \u0447\u0435\u0433\u043e \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c UDP \u0438 \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044e UDP hole punching. <\/p>\n<p>  \u0410 \u0434\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043d\u0430\u0434\u043e \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0438\u0442\u044c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u044b \u043d\u0430\u0434\u0435\u0436\u043d\u043e\u0441\u0442\u0438. \u041a\u0430\u043a \u043e\u0431\u044b\u0447\u043d\u043e \u0431\u044b\u0432\u0430\u0435\u0442, \u044f \u043d\u0430\u0447\u0430\u043b \u0442\u0440\u0443\u0434\u0438\u0442\u0441\u044f \u043d\u0430\u0434 \u0441\u0432\u043e\u0438\u043c \u043f\u0440\u043e\u0442\u043e\u043a\u043e\u043b\u043e\u043c \u043f\u043e\u0432\u0435\u0440\u0445 UDP \u043e\u0431\u0435\u0441\u043f\u0435\u0447\u0438\u0432\u0430\u044e\u0449\u0438\u043c \u043c\u043d\u0435 \u043d\u0430\u0434\u0435\u0436\u043d\u0443\u044e \u0434\u043e\u0441\u0442\u0430\u0432\u043a\u0443 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439. \u0418 \u043e\u043d \u0432\u0441\u0435 \u0442\u0430\u043a\u0438 \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f, \u043d\u043e \u0440\u0430\u0431\u043e\u0442\u0430\u043b \u0442\u043e\u043b\u044c\u043a\u043e \u043b\u043e\u043a\u0430\u043b\u044c\u043d\u043e. \u041f\u0440\u0438 \u0435\u0433\u043e \u0442\u0435\u0441\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u0438 \u0432 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0445 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445 \u043e\u043d, \u0432\u0438\u0434\u0438\u043c\u043e, \u043d\u0430\u0441\u0442\u043e\u043b\u044c\u043a\u043e \u043d\u0430\u0433\u0440\u0443\u0436\u0430\u043b \u0441\u0435\u0442\u044c, \u0447\u0442\u043e \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u043d\u043e\u0441\u0442\u044c\u044e \u0437\u0430\u0432\u0438\u0441\u0430\u043b \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440 :).<\/p>\n<p>  \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u044f \u043d\u0430\u0447\u0430\u043b \u0438\u0441\u043a\u0430\u0442\u044c \u0443\u0436\u0435 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 \u0438 \u043d\u0430\u0442\u043a\u043d\u0443\u043b\u0441\u044f \u043d\u0430 \u0441\u0430\u0442\u044c\u044e \u043d\u0430 \u0445\u0430\u0431\u0440\u0435, \u0433\u0434\u0435 \u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u0430\u044f \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0430 \u0431\u044b\u043b\u0430 \u0440\u0435\u0448\u0435\u043d\u0430 \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e Lidgren.Network. \u041e\u043d\u0430 \u0438 \u0431\u044b\u043b\u0430 \u0432\u044b\u0431\u0440\u0430\u043d\u0430.<\/p>\n<p>  \u041e\u0431\u0445\u043e\u0434 NAT \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u043d \u043d\u0430 \u0443\u0440\u043e\u0432\u043d\u0435 API. \u0421\u0445\u0435\u043c\u0430 \u043f\u0440\u043e\u0441\u0442\u0430\u044f, \u043d\u0443\u0436\u043d\u043e \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c, \u0447\u0442\u043e \u0431\u044b \u043f\u0438\u0440\u044b \u0443\u0437\u043d\u0430\u043b\u0438 \u0440\u0435\u0430\u043b\u044c\u043d\u044b\u0435 \u0430\u0434\u0440\u0435\u0441\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u0438\u0445 \u0432\u0438\u0434\u0438\u0442 \u0441\u0435\u0440\u0432\u0435\u0440. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u043e\u0434\u0438\u043d \u043f\u0438\u0440 \u0434\u043e\u043b\u0436\u0435\u043d \u043a\u0438\u043d\u0443\u0442\u044c \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0434\u0440\u0443\u0433\u043e\u043c\u0443. \u042d\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e \u043d\u0435 \u0434\u043e\u0439\u0434\u0435\u0442, \u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0441\u0442 \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u043d\u0430 \u0440\u043e\u0443\u0442\u0435\u0440\u0435, \u0447\u0442\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u044f \u043e\u0442 \u0442\u043e\u0433\u043e \u0430\u0434\u0440\u0435\u0441\u0430, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043e\u043d\u043e \u0431\u044b\u043b\u043e \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u0435\u043d\u043e \u043d\u0443\u0436\u043d\u043e \u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0442\u044c \u0438\u043c\u0435\u043d\u043d\u043e \u044d\u0442\u043e\u043c\u0443 \u043a\u043e\u043c\u043f\u044c\u044e\u0442\u0435\u0440\u0443. \u041f\u043e\u0441\u043b\u0435 \u044d\u0442\u043e\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u0441\u0435\u0440\u0432\u0435\u0440\u0430 \u0434\u0440\u0443\u0433\u043e\u0439 \u043f\u0438\u0440 \u0443\u0437\u043d\u0430\u0435\u0442, \u0447\u0442\u043e \u0435\u043c\u0443 \u0443\u0436\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u0441\u044f \u0438, \u0441\u043e\u0431\u0441\u0442\u0432\u0435\u043d\u043d\u043e, \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0435\u0442\u0441\u044f.<\/p>\n<p>  \u0418 \u0442\u0430\u043a, \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u0439:  <\/p>\n<ol>\n<li>\u041a\u043b\u0438\u0435\u043d\u0442 1 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0443, \u0447\u0442\u043e \u0445\u043e\u0447\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043a \u041a\u043b\u0438\u0435\u043d\u0442\u0443 2. (\u041a\u043e\u043c\u0430\u043d\u0434\u0430 ServerP2PConnectRequestCommand)<\/li>\n<li>\u0421\u0435\u0440\u0432\u0435\u0440 \u0434\u0435\u043b\u0435\u0433\u0438\u0440\u0443\u0435\u0442 \u0441\u0432\u043e\u044e \u0437\u0430\u0434\u0430\u0447\u0443 \u043a\u043b\u0430\u0441\u0441\u0443 P2PService<\/li>\n<li>P2PService \u0441\u043c\u043e\u0442\u0440\u0438\u0442 \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u043b\u0438\u0441\u044c \u043b\u0438 \u043a \u043d\u0435\u043c\u0443 \u0443\u0436\u0435 \u0442\u0430\u043a\u0438\u0435 \u043a\u043b\u0438\u0435\u043d\u0442\u044b \u0438 \u043d\u0435 \u0437\u043d\u0430\u0435\u0442 \u043b\u0438 \u043e\u043d \u0443\u0436\u0435 \u0438\u0445 \u0430\u0434\u0440\u0435\u0441\u0430. \u0415\u0441\u043b\u0438 \u043d\u0435\u0442 \u2014 \u043f\u0440\u043e\u0441\u0438\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u0442\u0435\u0445 \u043a\u0442\u043e \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d \u043d\u0435\u0431\u044b\u043b (\u041a\u043e\u043c\u0430\u043d\u0434\u0430 ClientConnectToP2PServiceCommand)<\/li>\n<li>\u041f\u043e\u0441\u043b\u0435 \u0438\u0445 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f, P2PService \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043e\u0434\u043d\u043e\u043c\u0443 \u0438\u0437 \u043d\u0438\u0445 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043e\u0436\u0438\u0434\u0430\u043d\u0438\u044f \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u041a\u043b\u0438\u0435\u043d\u0442 2. (ClientWaitPeerConnectionCommand)<\/li>\n<li>\u041a\u043b\u0438\u0435\u043d\u0442 \u043f\u043e\u043b\u0443\u0447\u0438\u0432\u0448\u0438\u0439 \u043a\u043e\u043c\u0430\u043d\u0434\u0443, \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u0442 \u0430\u0434\u0440\u0435\u0441 \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u043a \u043d\u0435\u043c\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u0441\u044f, \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u043d\u0430 \u043d\u0435\u0433\u043e \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. \u041d\u0430\u0447\u0438\u043d\u0430\u0435\u0442 \u043e\u0436\u0438\u0434\u0430\u0442\u044c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435 \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u0435\u0440\u0432\u0435\u0440\u0443 \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u043e \u0442\u043e\u043c, \u0447\u0442\u043e \u0433\u043e\u0442\u043e\u0432 \u043f\u0440\u0438\u043d\u044f\u0442\u044c \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435. (ServerP2PReadyAcceptCommand)<\/li>\n<li>\u041f\u043e\u0441\u043b\u0435 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0433\u043e\u0442\u043e\u0432\u043d\u043e\u0441\u0442\u0438, \u0441\u0435\u0440\u0432\u0435\u0440 \u0433\u043e\u0432\u043e\u0440\u0438\u0442 \u0434\u0440\u0443\u0433\u043e\u043c\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0443 (\u041a\u043b\u0438\u0435\u043d\u0442 1), \u0447\u0442\u043e \u0442\u043e\u0442 \u043c\u043e\u0436\u0435\u0442 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0430\u0442\u0441\u044f. (ClientConnectToPeerCommand)<\/li>\n<li>\u0421\u0432\u044f\u0437\u044c \u043c\u0435\u0436\u0434\u0443 \u043a\u043b\u0438\u0435\u043d\u0442\u0430\u043c\u0438 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u0430.<\/li>\n<\/ol>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/6ea\/c18\/8ce\/6eac188ce66bc50e9c31624874ba8203.png\"\/><\/p>\n<p>  \u0427\u0435\u0440\u043d\u044b\u043c\u0438 \u0441\u0442\u0440\u0435\u043b\u043a\u0430\u043c\u0438 \u043e\u0431\u043e\u0437\u043d\u0430\u0447\u0435\u043d\u044b \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u043a\u043e\u043c\u0430\u043d\u0434. \u041a\u0440\u0430\u0441\u043d\u044b\u043c \u0438\u043d\u0438\u0446\u0438\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 Lidgren.Network \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439.<\/p>\n<p>  \u0412\u0435\u0441\u044c \u044d\u0442\u043e\u0442 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043f\u0440\u044f\u0442\u0430\u043d \u0432 AsyncPeer, \u0438 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0432\u044b\u0437\u0432\u0430\u0442\u044c \u043c\u0435\u0442\u043e\u0434 SendMessage, \u0438 \u0435\u0441\u043b\u0438 \u043a\u043b\u0438\u0435\u043d\u0442 \u043d\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d, \u043e\u043d \u0441\u0430\u043c \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f, \u0438 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435. \u041b\u0438\u0431\u043e \u0441\u0440\u0430\u0437\u0443 \u043e\u0442\u043f\u0440\u0430\u0432\u0438\u0442, \u0435\u0441\u043b\u0438 \u0443\u0436\u0435 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d.<\/p>\n<p>  \u041a\u043e\u043c\u0430\u043d\u0434\u044b \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0439 \u0441\u0432\u044f\u0437\u0438 \u0438\u043d\u0438\u0446\u0438\u0438\u0440\u0443\u044e\u0442 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0435 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0438\u043d\u0430\u0447\u0435. \u041f\u0440\u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438 \u0433\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0439 \u043a\u043e\u043c\u043d\u0430\u0442\u044b \u0441\u0435\u0440\u0432\u0435\u0440 \u0441\u043e\u0437\u0434\u0430\u0435\u0442 \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0435 \u043a\u0430\u0440\u0442\u0443 \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0439. \u0412 \u043a\u043e\u0442\u043e\u0440\u043e\u0439 \u0437\u0430\u043f\u0438\u0441\u0430\u043d\u043e \u043a\u0443\u0434\u0430 \u0434\u043e\u043b\u0436\u0435\u043d \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u0442\u0441\u044f \u043a\u0430\u0436\u0434\u044b\u0439 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c \u0432 \u043a\u043e\u043c\u043d\u0430\u0442\u0435. \u0410 \u043a\u043e\u043c\u0430\u043d\u0434\u044b \u0432\u043e\u0441\u043f\u0440\u043e\u0438\u0437\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0433\u043e\u043b\u043e\u0441\u0430 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u044e\u0442\u0441\u044f \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e \u043c\u0435\u0442\u043e\u0434\u0430 AsyncPeer.SendMessageIfConnected, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u043e\u0441\u0442\u043e \u0432\u044b\u043a\u0438\u0434\u044b\u0432\u0430\u0435\u0442 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0435, \u0435\u0441\u043b\u0438 \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u044f \u043d\u0435\u0442.<\/p>\n<hr\/>\n<h4>\u041f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u0441\u043a\u0438\u0439 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441.<\/h4>\n<p>  \u041d\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u043a \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0435 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u044b.<br \/>  \u041e\u043d \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0430\u043d \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e WPF \u0438 \u043f\u0430\u0442\u0442\u0435\u0440\u043d\u0430 MVVM. \u041e\u0447\u0435\u043d\u044c \u0433\u0438\u0431\u043a\u0430\u044f \u0442\u0435\u0445\u043d\u043e\u043b\u043e\u0433\u0438\u044f, \u043f\u0440\u0430\u0432\u0434\u0430 \u0432 \u0432\u0435\u0440\u0441\u0438\u0438 3.5 \u043d\u0435\u043c\u043d\u043e\u0433\u043e \u0441\u044b\u0440\u043e\u0432\u0430\u0442\u0430, \u043d\u043e \u0442\u0435\u043c \u043d\u0435 \u043c\u0435\u043d\u0435\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043e\u0431\u043e\u0439\u0442\u0438 \u0441\u044b\u0440\u043e\u0432\u0430\u0442\u044b\u0435 \u043c\u0435\u0441\u0442\u0430. \u041a\u0430\u043a \u043d\u0430 \u043f\u0440\u0438\u043c\u0435\u0440 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u0430 Command \u0432\u0441\u0435 \u0435\u0449\u0435 \u043d\u0435 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u044b\u0435, \u0438 \u0434\u043b\u044f \u043d\u0438\u0445 \u043f\u0440\u0438\u0448\u043b\u043e\u0441\u044c \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u043e\u0431\u0435\u0440\u0442\u043a\u0443 CommandReference. <\/p>\n<p>  CommandReference \u0432 \u0434\u0430\u043d\u043d\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 \u0440\u0435\u0430\u043b\u044c\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443 \u2014 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0435 \u0441\u0432\u043e\u0439\u0441\u0442\u0432\u043e, \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u043e\u0432\u0435\u0441\u0438\u0442\u044c \u0431\u0438\u043d\u0434\u0438\u043d\u0433. \u0421\u0430\u043c\u0430 \u043e\u0431\u0435\u0440\u0442\u043a\u0430 \u0440\u0430\u0437\u043c\u0435\u0449\u0430\u0435\u0442\u0441\u044f \u0432 \u0441\u0442\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0435\u0441\u0443\u0440\u0441\u0430\u0445. \u0418 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043c\u0435\u0441\u0442\u0435, \u0440\u0435\u0430\u043b\u044c\u043d\u043e \u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043f\u0440\u0438\u0431\u0438\u043d\u0434\u0435\u043d\u0443\u044e \u043a\u043e\u043c\u0430\u043d\u0434\u0443.<\/p>\n<p>  \u0415\u0449\u0435 \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u043b\u043e\u0441\u044c \u0432\u043c\u0435\u0441\u0442\u043e \u043e\u0431\u0435\u0440\u0442\u043e\u043a \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c AttachedProperty \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432 \u0441\u0432\u043e\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u0438\u0437\u043c\u0435\u043d\u044f\u044e\u0442 \u043d\u0443\u0436\u043d\u044b\u0435.<\/p>\n<p>  \u0414\u043b\u044f \u043e\u043f\u043e\u0432\u0435\u0449\u0435\u043d\u0438\u044f \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043e\u0431 \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f\u0445 \u0431\u044b\u043b\u043e \u0440\u0435\u0448\u0435\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043e\u0431\u044b\u0442\u0438\u0439\u043d\u0443\u044e \u043c\u043e\u0434\u0435\u043b\u044c, \u043f\u0440\u0438 \u044d\u0442\u043e\u043c\u0443 \u0432 \u0441\u043e\u0431\u044b\u0442\u0438\u044f\u0445 \u043f\u0435\u0440\u0435\u0434\u0430\u0435\u0442\u0441\u044f \u0432\u0441\u044f \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u0430\u044f \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044f, \u0447\u0442\u043e \u0431\u044b \u043e\u0442\u043e\u0431\u0440\u0430\u0437\u0438\u0442\u044c \u0438\u0437\u043c\u0435\u043d\u0435\u043d\u0438\u044f.<\/p>\n<p>  \u0412 \u043f\u0440\u043e\u0447\u0435\u043c \u043e \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 \u043d\u0430\u043f\u0438\u0441\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u043d\u0435\u0447\u0435\u0433\u043e WPF \u043a\u0430\u043a WPF.      \t<\/p>\n<div class=\"clear\"><\/div>\n<\/p><\/div>\n<p> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"http:\/\/habrahabr.ru\/post\/228021\/\"> http:\/\/habrahabr.ru\/post\/228021\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"content html_format\">     \t\u041f\u0440\u0438\u0432\u0435\u0442 \u0425\u0430\u0431\u0440!<br \/>  \u0412 \u0441\u0442\u0430\u0442\u044c\u0435 \u044f \u043d\u0430\u043f\u0438\u0441\u0430\u043b, \u043e \u0442\u043e\u043c \u043a\u0430\u043a \u0440\u0430\u0437\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u043b \u0447\u0430\u0442. \u041e \u0435\u0433\u043e \u0430\u0440\u0445\u0438\u0442\u0435\u043a\u0442\u0443\u0440\u0435 \u0438 \u043e \u0442\u0435\u0445\u043d\u0438\u0447\u0435\u0441\u043a\u0438\u0445 \u0440\u0435\u0448\u0435\u043d\u0438\u044f\u0445 \u043f\u0440\u0438\u043d\u044f\u0442\u044b\u0445 \u0432 \u0445\u043e\u0434\u0435 \u0435\u0433\u043e \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u043a\u0438.<\/p>\n<p>  \u0427\u0430\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u0441\u043e\u0431\u043e\u0439 \u043a\u043b\u0438\u0435\u043d\u0442-\u0441\u0435\u0440\u0432\u0435\u0440\u043d\u043e\u0435 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435 \u0441 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u043c\u0438 p2p.<br \/>  \u0421 \u043f\u043e\u0434\u0434\u0435\u0440\u043a\u0436\u043e\u0439:  <\/p>\n<ul>\n<li>\u041b\u0438\u0447\u043d\u044b\u0445 \u0441\u043e\u043e\u0431\u0449\u0435\u043d\u0438\u0439.<\/li>\n<li>\u041a\u043e\u043c\u043d\u0430\u0442.<\/li>\n<li>\u041f\u0435\u0440\u0435\u0434\u0430\u0447\u0430\u0438 \u0444\u0430\u0439\u043b\u043e\u0432.<\/li>\n<li>\u0413\u043e\u043b\u043e\u0441\u043e\u0432\u043e\u0433\u043e \u0447\u0430\u0442\u0430.<\/li>\n<\/ul>\n<p>  <img decoding=\"async\" src=\"http:\/\/habrastorage.org\/getpro\/habr\/post_images\/767\/f07\/95a\/767f0795a486d76147e5fc9e4ddca1bb.png\"\/><\/p>\n<p>  \u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u043e\u0435\u043a\u0442\u0430: <a href=\"https:\/\/github.com\/Nirklav\/TCPChat\">GitHub<\/a>  <\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-228021","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/228021","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=228021"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/228021\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=228021"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=228021"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=228021"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}