コード例 #1
0
ファイル: Connection.cs プロジェクト: legend-plus/LegendPlus
 public override void _Process(float delta)
 {
     if (connected && !client.IsConnectedToHost())
     {
         connected    = false;
         disconnected = true;
     }
     if (connected)
     {
         getPackets();
     }
     if (disconnected)
     {
         GD.Print(String.Format("Reconnecting to {0}:{1}", ip, port));
         client.ConnectToHost(ip, port);
         if (client.IsConnectedToHost())
         {
             client.SetNoDelay(true);
             client.SetBlockSignals(true);
             wrapped_client = new PacketPeerStream();
             wrapped_client.SetStreamPeer(client);
             connected    = true;
             disconnected = false;
             GD.Print("Reconnected.");
         }
         else
         {
             GD.Print("Failed to connect.");
         }
     }
 }
コード例 #2
0
        public static void Update()
        {
            if (socket == null || socket.IsConnectedToHost() == false)
            {
                return;
            }

            Recv();
        }
コード例 #3
0
ファイル: MinecraftClient.cs プロジェクト: kotyk7/Godotcraft
        public override void _Process(float delta)
        {
            if (!client.IsConnectedToHost())
            {
                SetProcess(false);
                return;
            }

            // read incoming packet
            while (client.GetAvailableBytes() > 0)
            {
                // read len
                int len = dataTypes.ReadNextVarIntFromStream(client);
                if (len == 0)
                {
                    GD.Print("Got zero length packet");
                }
                else
                {
                    handlePacket(readPacketInternal(len));
                }
            }

            // send queued packets
            while (packetQueue.Count > 0)
            {
                sendPacketInternal(packetQueue.Dequeue());
            }
        }