本文整理汇总了C#中IPEndPoint类的典型用法代码示例。如果您正苦于以下问题:C# IPEndPoint类的具体用法?C# IPEndPoint怎么用?C# IPEndPoint使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IPEndPoint类属于命名空间,在下文中一共展示了IPEndPoint类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: StartListener
private void StartListener(IPEndPoint endPoint)
{
_listener = new TcpListener(endPoint);
_listener.Start(5);
_log.WriteLine("Server {0} listening", endPoint.Address.ToString());
_listener.AcceptTcpClientAsync().ContinueWith(t => OnAccept(t), TaskScheduler.Default);
}
示例2: SyncClient
public SyncClient()
{
var hostName = Dns.GetHostName();
var localAdd = Dns.GetHostEntry(hostName).AddressList[0];
var localEP = new IPEndPoint(localAdd, 0);
TcpClient = new TcpClient(); //new TcpClient(localEP);
}
示例3: init
public void init()
{
IP = "192.168.15.11";
port = 8051;
remoteEndPoint = new IPEndPoint(IPAddress.Parse(IP), port);
client = new UdpClient();
}
示例4: Main
public static void Main()
{
byte[] data = new byte[1024];
IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 9876);
UdpClient newsock = new UdpClient(ipep);
Console.WriteLine("Waiting for a client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 9877);
data = newsock.Receive(ref sender);
Console.WriteLine("Message received from {0}:", sender.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length));
string msg = Encoding.ASCII.GetString(data, 0, data.Length);
data = Encoding.ASCII.GetBytes(msg);
newsock.Send(data, data.Length, sender);
while(true){
data = newsock.Receive(ref sender);
Console.WriteLine(Encoding.ASCII.GetString(data, 0, data.Length));
newsock.Send(data, data.Length, sender);
}
}
示例5: Start
void Start()
{
Application.runInBackground = true;
Debug.Log("Net listener started!");
// Data buffer for incoming data.
bytes = new byte[1024];
// Connect to a remote device.
try
{
// Establish the remote endpoint for the socket.
// This example uses port 30303 on the local computer.
IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
IPAddress ipAddress = ipHostInfo.AddressList[0];
remoteEP = new IPEndPoint(ipAddress, 30303);
// Create a TCP/IP socket.
socket = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp);
socket.Connect(remoteEP);
Debug.Log("Socket connected to {0}" +
socket.RemoteEndPoint.ToString());
idMap = new Dictionary<int, GameObject>();
socket.Blocking = false;
}
catch (Exception e)
{
Debug.Log(e.ToString());
}
}
示例6: Start
// Use this for initialization
void Start()
{
// Set up Server End Point for sending packets.
IPHostEntry serverHostEntry = Dns.GetHostEntry(serverIp);
IPAddress serverIpAddress = serverHostEntry.AddressList[0];
serverEndPoint = new IPEndPoint(serverIpAddress, serverPort);
Debug.Log("Server IPEndPoint: " + serverEndPoint.ToString());
// Set up Client End Point for receiving packets.
IPHostEntry clientHostEntry = Dns.GetHostEntry(Dns.GetHostName());
IPAddress clientIpAddress = IPAddress.Any;
foreach (IPAddress ip in clientHostEntry.AddressList) {
if (ip.AddressFamily == AddressFamily.InterNetwork) {
clientIpAddress = ip;
}
}
clientEndPoint = new IPEndPoint(clientIpAddress, serverPort);
Debug.Log("Client IPEndPoint: " + clientEndPoint.ToString());
// Create socket for client and bind to Client End Point (Ip/Port).
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
try {
clientSocket.Bind(clientEndPoint);
}
catch (Exception e) {
Debug.Log("Winsock error: " + e.ToString());
}
}
示例7: ReceiveData
private void ReceiveData()
{
client = new UdpClient(8000);
while (running)
{
try
{
IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
byte[] data = client.Receive(ref anyIP);
string text = Encoding.UTF8.GetString(data);
Debug.Log("Input "+text);
string[] info = text.Split(':');
inputText = text;
if(info[0].Equals("speed")){
speed= info[1];
}
if(info[0].Equals("turn")){
axis= info[1];
}
}
catch (Exception err)
{
running =false;
print(err.ToString());
}
}
}
示例8: Connect
void Connect()
{
Debug.Log ("Connect");
//if (clientSocket != null && clientSocket.Connected) Disconnect();
//var ipAddress = Dns.GetHostAddresses ("localhost");
//IPEndPoint ipEndPoint = new IPEndPoint(ipAddress[0], 1234);
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(hostIp), port);
// Create Socket
AddressFamily family = AddressFamily.InterNetwork;
SocketType sokType = SocketType.Stream;
ProtocolType proType = ProtocolType.Tcp;
clientSocket = new Socket(family, sokType, proType);
Debug.Log("Connecting to localhost");
clientSocket.Connect (ipEndPoint);
// arriving here means the operation completed asyncConnect.IsCompleted = true)
// but not necessarily successfully
if (clientSocket.Connected == false)
{
Debug.Log(".client is not connected.");
return;
}
Debug.Log(".client is connected.");
clientSocket.Blocking = false;
}
示例9: UDPServer
public UDPServer()
{
try
{
// Iniciando array de clientes conectados
this.listaClientes = new ArrayList();
entrantPackagesCounter = 0;
sendingPackagesCounter = 0;
// Inicializando el delegado para actualizar estado
//this.updateStatusDelegate = new UpdateStatusDelegate(this.UpdateStatus);
// Inicializando el socket
serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
// Inicializar IP y escuhar puerto 30000
IPEndPoint server = new IPEndPoint(IPAddress.Any, 30001);
// Asociar socket con el IP dado y el puerto
serverSocket.Bind(server);
// Inicializar IPEndpoint de los clientes
IPEndPoint clients = new IPEndPoint(IPAddress.Any, 0);
// Inicializar Endpoint de clientes
EndPoint epSender = (EndPoint)clients;
// Empezar a escuhar datos entrantes
serverSocket.BeginReceiveFrom(this.dataStream, 0, this.dataStream.Length, SocketFlags.None, ref epSender, new AsyncCallback(ReceiveData), epSender);
}
catch (Exception ex)
{
//Debug.Log("Error al cargar servidor: " + ex.Message+ " ---UDP ");
}
}
示例10: Start
public void Start(int port)
{
if (listener != null && listener.Server.IsBound)
{
return;
}
this.port = port;
IPEndPoint ipEnd = new IPEndPoint(IPAddress.Any, port);
listener = new TcpListener(ipEnd);
try
{
listener.Start();
running = true;
if (LOGGER.IsInfoEnabled)
{
LOGGER.Info("Push Server Simulator is successfully started on port " + port.ToString());
}
}
catch (Exception e)
{
if (LOGGER.IsErrorEnabled)
{
LOGGER.Error("Error occured while trying to start Push Server Simulator on port " + port.ToString() + " . Message: " + e.Message);
}
}
thread = new Thread(new ThreadStart(listen));
thread.Start();
}
示例11: ConnectSocket
Socket ConnectSocket(string server, int port) {
Socket s = null;
IPHostEntry hostEntry = null;
// Get host related information.
hostEntry = Dns.GetHostEntry(server);
// Loop through the AddressList to obtain the supported AddressFamily. This is to avoid
// an exception that occurs when the host IP Address is not compatible with the address family
// (typical in the IPv6 case).
foreach(IPAddress address in hostEntry.AddressList) {
IPEndPoint ipe = new IPEndPoint(address, port);
Socket tempSocket = new Socket(ipe.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(ipe);
if(tempSocket.Connected) {
s = tempSocket;
break;
} else {
continue;
}
}
return s;
}
示例12: Connect
public bool Connect()
{
try
{
serverRemote = new IPEndPoint(IPAddress.Parse(ipAddress), portNumber);
udpClient = new UdpClient();
udpClient.Connect(serverRemote);
if(udpClient.Client.Connected)
{
Debug.Log("connected!");
sendUDPPacket("ANYONE OUT THERE?");
//byte[] data = Encoding.UTF8.GetBytes(toSend);
//client.Send(data, data.Length, serverRemote);
//client.SendTimeout(serverRemote, data);
}
}
catch(Exception ex)
{
print ( ex.Message + " : OnConnect");
}
isConnected = true;
if ( udpClient == null ) return false;
return udpClient.Client.Connected;
}
示例13: Receive
public Byte[] Receive(ref IPEndPoint remoteEP)
{
Contract.Ensures(Contract.Result<Byte[]>() != null);
Contract.Ensures(Contract.Result<Byte[]>().Length > 0); // after reading the code
return default(Byte[]);
}
示例14: ConnectToServer
void ConnectToServer()
{
clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
//服务器IP地址
IPAddress ip = IPAddress.Parse(ipaddress);
//服务器端口
IPEndPoint ipEndpoint = new IPEndPoint(ip, port);
// clientSocket.Connect(new IPEndPoint(IPAddress.Parse(ipaddress), port));
//这是一个异步的建立连接,当连接建立成功时调用connectCallback方法
IAsyncResult result = clientSocket.BeginConnect(ipEndpoint, new AsyncCallback(connectCallback), clientSocket);
//这里做一个超时的监测,当连接超过5秒还没成功表示超时
bool success = result.AsyncWaitHandle.WaitOne(5000, true);
if (!success)
{
//超时
//Closed();
Debug.Log("connect Time Out");
}
else
{
//与socket建立连接成功,开启线程接受服务端数据。
//worldpackage = new List<JFPackage.WorldPackage>();
//Thread thread = new Thread(new ThreadStart(ReceiveSorket));
t = new Thread(RecevieMessage);
t.IsBackground = true;
t.Start();
}
}
示例15: Connection
public void Connection()
{
if(!connected)
{
string ip = IP.text;
Debug.Log("[CLIENT] Connecting to Server [" + ip + ":" + port + "]");
try
{
IPAddress ipAdress = IPAddress.Parse(ip);
IPEndPoint remoteEP = new IPEndPoint(ipAdress, port);
PlayerPrefs.SetString ("IP_Address", ip);
// Create a TCP/IP socket.
client = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
// Connect to the remote endpoint.
client.BeginConnect( remoteEP, new AsyncCallback(ConnectCallback), client);
connectDone.WaitOne();
Receive(client);
}
catch (Exception e)
{
distributor.closeConnection();
}
}
else
{
Application.Quit();
}
}