임시
<C#과 아이폰간의 UDP 소켓 통신 샘플소스>
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace UDPServer
{
class App
{
//port 번호
private const int portNum = 5432;
[STAThread]
static void Main(string[] args)
{
//
// TODO: Add code to start application here
//
try
{
byte[] buffer = new Byte[100];
int numReceived = 0;
//본인 IP
EndPoint localEP = new IPEndPoint(IPAddress.Parse("192.168.123.132"), portNum);
EndPoint remoteEP = new IPEndPoint(IPAddress.Any, 0);
Socket udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
udpSocket.Bind(localEP);
Console.WriteLine("<<UDP 서버를 시작합니다...>>");
while (true)
{
numReceived = udpSocket.ReceiveFrom(buffer, ref remoteEP);
//서버-클라이언트 간의 인코딩 통일(UTF8)
string s = Encoding.UTF8.GetString(buffer, 0, numReceived);
Console.WriteLine("Echo : {0}", s);
udpSocket.SendTo(buffer, numReceived, SocketFlags.None, remoteEP);
}
}
catch (SocketException se)
{
Console.WriteLine(se.ToString());
}
}
}
}