Exemple #1
0
        // primarily for use of NetPacketReferenceController, or equivalent, to resent non-acked sent packets
        // note that we're still going to rewrite shared key
        public void RawSend(byte[] packet)
        {
            int offset = 0;

            new BinaryPacker().WriteValueToBuffer(packet, ref offset, sharedsecretexchange.SharedSecretKey);
            if (isserver)
            {
                networkimplementation.Send(connectioninfo.Connection, packet);
            }
            else
            {
                networkimplementation.Send(packet);
            }
        }
            public void Go(string ipaddress, int port)
            {
                INetworkImplementation net = NetworkImplementationFactory.CreateNewInstance();

                net.ConnectAsClient(ipaddress, port);
                net.ReceivedPacket += new Level1ReceivedPacketHandler(net_ReceivedPacket);
                net.Send(Encoding.UTF8.GetBytes("Hi, this is a test"));
                while (true)
                {
                    net.Tick();
                    Thread.Sleep(50);
                }
            }
Exemple #3
0
        //~STUN()
        //{
        //  network.ReceivedPacket -= packethandler; // not sure if necessary?
        //}
        public STUN( INetworkImplementation network, GotExternalAddress callback )
        {
            LogFile.WriteLine( "STUN " + network.LocalIPAddress + " " + network.LocalPort + " " + callback.Target + " " + callback.Method );

            this.network = network;
            this.callback = callback;

            packethandler = new Level1ReceivedPacketHandler( network_ReceivedPacket );
            network.ReceivedPacket += packethandler;

            byte[] bytes = CreateSTUNBindingRequestPacket();

            network.Send( GetStunServerEndpoint(), bytes );
        }
Exemple #4
0
        //~STUN()
        //{
        //  network.ReceivedPacket -= packethandler; // not sure if necessary?
        //}

        public STUN(INetworkImplementation network, GotExternalAddress callback)
        {
            LogFile.WriteLine("STUN " + network.LocalIPAddress + " " + network.LocalPort + " " + callback.Target + " " + callback.Method);

            this.network  = network;
            this.callback = callback;

            packethandler           = new Level1ReceivedPacketHandler(network_ReceivedPacket);
            network.ReceivedPacket += packethandler;

            byte[] bytes = CreateSTUNBindingRequestPacket();

            network.Send(GetStunServerEndpoint(), bytes);
        }
 void net_ReceivedPacket(INetworkImplementation source, ConnectionInfo connectioninfo, byte[] data, int offset, int length)
 {
     LogFile.WriteLine("Received packet: " + Encoding.UTF8.GetString(data));
     net.Send(connectioninfo.Connection, Encoding.UTF8.GetBytes("Hello from server!"));
 }