Beispiel #1
0
    public static void Run(string c)
    {
        var p = c.Split(".");

        try
        {
            UdpClient uClient = new UdpClient();

            var ip = new Cosmos.System.Network.IPv4.Address((byte)int.Parse(p[0]), (byte)int.Parse(p[1]),
                                                            (byte)int.Parse(p[2]), (byte)int.Parse(p[3]));
            var    host    = new Cosmos.System.Network.IPv4.EndPoint(ip, 80);
            byte[] payload = Encoding.ASCII.GetBytes("abcdefghijklmnopqrstuvwabcdefghi");

            try
            {
                uClient.Connect(ip, 80);
                uClient.Send(payload, ip, 80);
                uClient.Receive(ref host);
                Console.WriteLine("Connected!");
                uClient = null;
            }
            catch (NullReferenceException e)
            {
                Console.WriteLine("Connection Failed");
                Console.WriteLine(e.Message);
            }
        }
        catch
        {
            Console.WriteLine("Connection Failed");
        }
    }
Beispiel #2
0
        internal void receiveData(IPv4.UDPPacket packet)
        {
            byte[]        data   = packet.UDP_Data;
            IPv4.EndPoint source = new IPv4.EndPoint(packet.SourceIP, packet.SourcePort);

            Sys.Console.WriteLine("Received " + data.Length + " bytes data from " + source.ToString());

            this.rxBuffer.Enqueue(new DataGram(data, source));
        }
Beispiel #3
0
        public byte[] Receive(ref IPv4.EndPoint source)
        {
            if (this.rxBuffer.Count < 1)
            {
                return(null);
            }

            DataGram packet = rxBuffer.Dequeue();

            source.address = packet.source.address;
            source.port    = packet.source.port;

            return(packet.data);
        }
Beispiel #4
0
 internal DataGram(byte[] data, IPv4.EndPoint src)
 {
     this.data   = data;
     this.source = src;
 }
Beispiel #5
0
 internal DataGram(byte[] data, IPv4.EndPoint src)
 {
     this.data = data;
     this.source = src;
 }
Beispiel #6
0
        internal void receiveData(IPv4.UDPPacket packet)
        {
            byte[] data = packet.UDP_Data;
            IPv4.EndPoint source = new IPv4.EndPoint(packet.SourceIP, packet.SourcePort);

            Sys.Console.WriteLine("Received " + data.Length + " bytes data from " + source.ToString());

            this.rxBuffer.Enqueue(new DataGram(data, source));
        }