Показаны сообщения с ярлыком network. Показать все сообщения
Показаны сообщения с ярлыком network. Показать все сообщения

четверг, 5 апреля 2012 г.

UDP


MSDN Magazine > Issues and Downloads > 2006 > February >  UDP Delivers: Take Total Control Of Your Networ...
UDP Delivers
Take Total Control Of Your Networking With .NET And UDP
Yaniv Pessach

This article discusses:
  • The pros and cons of TCP and UDP
  • Building UDP into your applications
  • Reliability protocols and security issues
  • UDP support in Windows Communication Foundation

Сервер SmartFox

http://www.smartfoxserver.com/

Недостатки: разработка под JAVA
Стоимость: 1500$+

Сервер Photone

http://www.exitgames.com/

Недостатки: Windows Only
Стоимость: 800$ инди. (<10000$/мес.)

Python UDP, Twisted


from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor

class Echo(DatagramProtocol):

    def datagramReceived(self, data, (host, port)):
        print "received %r from %s:%d" % (data, host, port)
        self.transport.write(data, (host, port))

reactor.listenUDP(12000, Echo())
reactor.run()

C# UDP

Реализация UDP на C#


using System;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.IO;

namespace LidTest
{



class MainClass
{

static UdpClient usck;

    static void recv(IAsyncResult res) {
            IPEndPoint remote = new IPEndPoint(IPAddress.Any,0);          
            byte[] data = usck.EndReceive(res, ref remote);

            // do something with data received from remote
            Console.WriteLine(remote.Address.ToString() + ": " + Encoding.ASCII.GetString(data));

            // get next packet
            usck.BeginReceive(recv, null);

    }


public static void Main (string[] args)
{

            usck = new UdpClient("localhost",12000);
            Console.WriteLine("waiting for packets, hit enter to stop");          
            usck.BeginReceive(new AsyncCallback(recv), null);
//usck.Send(new byte[] {1,2,3} , 3);

System.IO.MemoryStream ms = new System.IO.MemoryStream();

BinaryWriter bw = new BinaryWriter(ms);
bw.Write((Int16)(2));
bw.Write("ПИП");
bw.Write((Int16)(4));
bw.Write(true);
bw.Flush();
byte[] b =ms.ToArray();
usck.Send(b,b.Length);


            Console.ReadLine();
            usck.Close();
}
}
}