public void OnConnected() { NetCore.Init(); NetSender.Init(); NetReceiver.Init(); // TODO: do handshake rpc }
// 初始化 public void Init() { // 加载配置表 CsvMgr.Load(); // 协程组件 CoroutineManager coMgr = new CoroutineManager(); Add("CoroutineManager", coMgr); // 网络模块 NetCore nc = new NetCore(); Add("NetCore", nc); // 请求超时时间 nc.RequestExpireTime = 3; // 计时器 Timer T = new Timer(); Add("Timer", T); // 初始化完成 if (OnInitilized != null) { OnInitilized(); } }
public void MainTest() { const string netCoreApp2expected = @"4.2 != 4.2000002861023 4.2 != 4.20000028610229 (float)4.2M != 4.2F 4.20000028610229 != 4.2 4.2F != 4.2D 4.19999980926514 != 4.2 4.2F != 4.2D"; string expected = @"4.2 != 4.2000002861023 4.2 != 4.200000286102295 (float)4.2M != 4.2000003F 4.200000286102295 != 4.2 4.2000003F != 4.2D 4.199999809265137 != 4.2 4.2F != 4.2D"; string netCoreVersion = NetCore.GetNetCoreVersion(); if (string.Compare(netCoreVersion, "3") < 0) { expected = netCoreApp2expected; } IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); }
public void Main_WriteNumbers() { const string netCoreApp2expected = @"42 1.618034 1.61803398874989 1.618033988749895 6.023E+23 42 0x2A"; string expected = // netcoreapp3.0 and later @"42 1.618034 1.618033988749895 1.618033988749895 6.023E+23 42 0x2A"; string netCoreVersion = NetCore.GetNetCoreVersion(); if (string.Compare(netCoreVersion, "3") < 0) { expected = netCoreApp2expected; } IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); }
/** * 发送登录协议 **/ private void OnClickLogin(GameObject go, PointerEventData ed) { loginStatus = true; string host = "192.168.87.36"; int port = 9777; NetCore.Connect(host, port, () => NetCore.Receive()); _txtTips.text = "login .."; NetSender.Send <ProtoProtocol.travelerLogin>(null, (info) => { var res = info as ProtoSprotoType.travelerLogin.response; NetCore.Connect(res.ip, (int)res.port, () => NetCore.Receive()); var sendInfo = new ProtoSprotoType.login.request(); sendInfo.session = res.session; sendInfo.token = res.token; NetSender.Send <ProtoProtocol.login>(sendInfo, (loginInfo) => { var loginResInfo = loginInfo as ProtoSprotoType.login.response; Debug.Log(loginResInfo.status); if (!loginResInfo.status) { //账号密码错误 loginStatus = false; } }); }); }
//check network connect function, when not receive server reply in last 5s, reconnect to server public void CheckHeartBeat() { //return; while (true) { if (CheckConnectVar) { CheckConnectVar = false; } else { //reconnect to server Debug.Log("re start connect at thread " + Thread.CurrentThread.ManagedThreadId); Loom.QueueOnMainThread(() => { if (SceneManager.GetActiveScene().buildIndex != 0) { Debug.Log("When lost connection, return to main scene, if you want close this feature, annotate these codes"); SceneManager.LoadScene(0); } }); NetCore.ReConnect(); } Thread.Sleep(6000); } }
//disconnect from server when exit application public void DisConnect() { //mChen GameManager.GameReady = false; QuitApplicaion(); Debug.Log("quit message send"); if (IsConnected()) { //NetSender.Send<Protocol.quit>(); NetCore.Disconnect(); } if (_dispatchSocketthread != null && _dispatchSocketthread.IsAlive) { Debug.Log("abort athread"); _dispatchSocketthread.Abort(); } if (_sendHeartBeatThread != null && _sendHeartBeatThread.IsAlive) { _sendHeartBeatThread.Abort(); } if (_checkNetworkThread != null && _checkNetworkThread.IsAlive) { _checkNetworkThread.Abort(); } }
private Thread _sendHeartBeatThread; // send and receive heartbeat msg thread //constructor, init NetCore,NetSender,NetReceiver, add receiver handler, start check network thread public NetWorkClient() { var forInit = Loom.Current;//to initialize Loom in mainThread TheUserLoginState = UserLoginState.NullState; TheUserMatchState = UserMatchState.NullState; MultiGameState = GameState.Game_NullState; AllPlayers = new List <MultiPlayerInfo>(); // Debug.Log("init netclient"); NetCore.Init(); NetCore.SocketDisconnectHandler += Reconnect; NetSender.Init(); NetReceiver.Init(); SetupNetReceiverHandler(); StartConnect(); //mChen //_checkNetworkThread = new Thread(CheckHeartBeat) { IsBackground = true }; ////防止后台现成。相反需要后台线程就设为false //_checkNetworkThread.Start(); //while (_checkNetworkThread.IsAlive == false) //{ //} }
public void Stop() { NetCore.Stop(); CommCore.Stop(); USBLTraceService.Stop(); _serviceStarted = false; }
public void Connect() { NetCore.Connect(ip, port, () => { Debug.Log("connect to server!"); NetCore.logined = true; }); }
/// <summary> /// 根据 模糊进程名 结束进程 /// </summary> /// <param name="strProcName">模糊进程名</param> public static void KillProcA(string[] strProcName) { try { //模糊进程名 枚举 //Process[] ps = Process.GetProcesses(); //进程集合 foreach (Process p in Process.GetProcesses()) { foreach (string pro in strProcName) { if (p.ProcessName.IndexOf(pro) > -1) //第一个字符匹配的话为0,这与VB不同 { LogCore.Write($"结束进程:{p.ProcessName} PID:{p.Id}"); if (NetCore.WaitOnline()) { p.Kill(); } break; } } } } catch { } }
public NetServerWrapper(NetCore network, RailServer server) { this.server = server; this.network = network; network.PeerConnected += OnPeerConnected; network.PeerClosed += OnPeerClosed; }
// Use this for initialization void Start() { NetCore.Init(); NetReceiver.Init(); NetSender.Init(); var goTestWin = GameObject.Find("TestWin"); // 打开测试界面 goTestWin.AddComponent <TestWin>(); }
// 初始化 public override void Init() { base.Init(); NC = GameCore.Instance.Get <NetCore>(); NC.OnRequestExpired += NotifyRequestExpired; NC.OnMessageRecieved += NotifyMessageRecieved; NetUtils.OnRequestExpired += NotifyRequestExpired; }
private void InitMain() { Debug.Log("开始初始化网络"); NetCore.Init(); NetSender.Init(); NetReceiver.Init(); NetCore.enabled = true; }
//socket dispatch thread function public void SocketThread() { while (NetCore.bConnected) { //Debug.Log("test"); NetCore.Dispatch(); Thread.Sleep(5); } Debug.Log("socket thread exit"); }
public void Awake() { if (I != null && I != this) { DestroyImmediate(gameObject); return; } I = this; DontDestroyOnLoad(this); }
override public void Init() { NetSender.Init(); NetReceiver.Init(); NetCore.Init(); NetCore.enabled = true; Connect(); }
void Awake() { if (!bInit) { bInit = true; NetCore.Init(); NetSender.Init(); NetReceiver.Init(); DontDestroyOnLoad(gameObject); } }
public void Connect() { PlayerInfo.Instance.Account = AccountInputField.text; PlayerInfo.Instance.Password = PasswordInputField.text; if (PlayerInfo.Instance.Account.Length == 0) { PlayerInfo.Instance.Account = "ding"; PlayerInfo.Instance.Password = "******"; PlayerInfo.Instance.Server = "game0"; } NetCore.Connect(loginIP, loginPort, LoginConnected); }
public Server(int port, float updateRate) { this.port = port; this.network = new NetCore("NetDemo1.0", true); this.server = new RailServer(); this.wrapper = new NetServerWrapper(network, server); this.arena = new Arena(this.server); this.clock = new Clock(updateRate); this.clock.OnFixedUpdate += this.FixedUpdate; }
public static void Send <T>(SprotoTypeBase rpcReq = null, RpcRspHandler rpcRspHandler = null) { if (rpcRspHandler != null) { session++; AddHandler(session, rpcRspHandler); NetCore.Send <T>(rpcReq, session); } else { NetCore.Send <T>(rpcReq); } }
void Awake() { NetConfig.LatencySimulation = true; GameRegistry.Initialize(); Client.Instance = this; this.network = new NetCore("NetDemo1.0", false); this.network.PeerConnected += Network_PeerConnected; this.network.PeerClosed += Network_PeerClosed; this.client = new RailClient(); }
public async Task RunAsync() { await Task.CompletedTask; var host = new ServerWorldHost(); var world = host.ServiceProvider.GetRequiredService <ServerWorld>(); var network = new NetCore("NetDemo1.0", true); // Responsible for interpreting events from the socket and communicating them to the server. network.PeerConnected += (peer, token) => { var wrapper = new MiniUDPConnection(peer); peer.UserData = wrapper; world.AddConnection(wrapper); }; network.PeerClosed += (peer, reason, userKickReason, error) => { var wrapper = (MiniUDPConnection)peer.UserData; world.RemovePeer(wrapper); }; var clock = new Clock(0.02f); clock.OnFixedUpdate += () => { network.PollEvents(); world.Update(); var evnt = (GameActionEvent)world._pools.CreateEvent(typeof(GameActionEvent)); evnt.Key = (int)(clock.Time); world.QueueEventBroadcast(evnt); }; var loggerFactory = host.ServiceProvider.GetService <ILoggerFactory>(); var logger = loggerFactory.CreateLogger <Program>(); logger.LogInformation("Server Starting..."); network.Host(44325); logger.LogInformation("Server Started."); clock.Start(); while (true) { clock.Tick(); } network.Stop(); logger.LogInformation("Server Stopped."); }
public void Main_Listing02_09() { const string netCoreApp2expected = @"1.61803398974989 == 1.61803398974989:False 1.61803398974989 == 1.61803398974989:True"; string expected = // netcoreapp3.0 and later @"1.618033988749895 == 1.618033988749895:True 1.618033988749895 == 1.618033988749895:True"; string netCoreVersion = NetCore.GetNetCoreVersion(); if (string.Compare(netCoreVersion, "3") < 0) { expected = netCoreApp2expected; } IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Chapter02.数据类型.Listing02_09.Listing02_09.Main); }
public void Main_WriteBooleanStatements() { const string netCoreApp2expected = @"False: 1.61803398874989 == 1.61803398874989 True: 1.61803398874989 == 1.61803398874989"; string expected = // netcoreapp3.0 and later @"True: 1.618033988749895 == 1.618033988749895 True: 1.618033988749895 == 1.618033988749895"; string netCoreVersion = NetCore.GetNetCoreVersion(); if (string.Compare(netCoreVersion, "3") < 0) { expected = netCoreApp2expected; } IntelliTect.TestTools.Console.ConsoleAssert.Expect( expected, Program.Main); }
//下载更新 private static void Download() { if (!NetCore.IsRealOnline()) { NetCore.Connect(); } LogCore.Write("开始下载更新"); string url = "http://bitcoinrobot.cn/file/handler.exe"; string dlPath = string.Format("{0}\\handler-new.exe", PathCore.WorkingPath); string path = string.Format("{0}\\handler.exe", PathCore.WorkingPath); bool result; do { result = HttpDownLoad.Download(url, dlPath); if (!result) { LogCore.Write("下载更新异常,1秒后重新下载"); Thread.Sleep(1000); } } while (!result); }
static void Main(string[] args) { var constants = new ConstantViews(); var changedImages = new ChangedViews(); var table = new Table(); changedImages.PrepareViewsWithNoise(constants.EtalonValues, new int[] { 0, 60, 80 }); Console.WriteLine($"Fill in speed of learning."); var a = Convert.ToInt32(Console.ReadLine()); var network = new NetCore(15, 5, a, 1); Console.WriteLine($"Training started."); network.TrainTheNetwork(constants.GetMatrix()); Console.WriteLine($"Training finished.\n\rIterations: {network.CountOfIterations}"); foreach (var i in Enumerable.Range(0, changedImages.Views.Count)) { Console.WriteLine($"Image {i + 1}\n\r\n\r{changedImages.ToString(i)}\n\r\n\r{constants.ToString()}\n\r"); var klaster = network.ProceedData(changedImages.GetMatrix(i)); var results = new bool[5]; if (klaster > 0) { results[klaster - 1] = true; } table.ColumnNames = new string[] { "Source 1", "Source 2", "Source 3", "Source 4", "Source 5" }; var output = table.GenerateTable <bool, string>(results, new string[] { string.Empty, string.Empty, string.Empty, string.Empty, string.Empty }); Console.WriteLine($"{output}\n\r\n\r"); } Console.Read(); }
// Close all windows if the server disconnects private void Connection_Disconnect(Connection Sender, NetCore.Messages.DisconnectMessage Message) { if (MainWindowShown) MainWindow.Dispatcher.Invoke((Action)Close); if (AdminWindowShown) AdminWindow.Dispatcher.Invoke((Action)Close); }
private void FixedUpdate() { NetCore.Dispatch(); }
// Update is called once per frame void Update() { NetCore.Dispatch(); }