本文整理汇总了C#中System.Net.EndPoint.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# EndPoint.ToString方法的具体用法?C# EndPoint.ToString怎么用?C# EndPoint.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.EndPoint
的用法示例。
在下文中一共展示了EndPoint.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: run
public void run() {
//MESSAGE
System.Windows.Forms.MessageBox.Show("Waiting for client...");
IPEndPoint sender = new IPEndPoint(IPAddress.Any, this.PORT);
client = (EndPoint)sender;
//MESSAGE
System.Windows.Forms.MessageBox.Show("Client Connected at : {0} ", client.ToString());
while (isRunning) {
data = new byte[1024];
recv = serverSocket.ReceiveFrom(data, ref client);
if (recv == 0)
{
System.Windows.Forms.MessageBox.Show("Client Connection Lost at : {0} ", client.ToString());
isRunning = false;
break;
}
//MESSAGE
System.Windows.Forms.MessageBox.Show(Encoding.ASCII.GetString(data, 0, recv) + " " + client.ToString());
//PARSE THE DATA AND UPDATE THE AIRCRAFT
}
serverSocket.Close();
}
示例2: Connect
public void Connect(EndPoint endPoint)
{
byte[] data = new byte[1024];
string input, stringData;
int recv;
Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
int sockopt = (int)server.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout);
Console.WriteLine("Default timeout: {0}", sockopt);
server.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, _timeout);
sockopt = (int)server.GetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout);
Console.WriteLine("New timeout: {0}", sockopt);
string welcome = "Hello, are you there?";
data = Encoding.ASCII.GetBytes(welcome);
server.SendTo(data, data.Length, SocketFlags.None, endPoint);
data = new byte[1024];
try
{
Console.WriteLine("Waiting from {0}:", endPoint.ToString());
recv = server.ReceiveFrom(data, ref endPoint);
Console.WriteLine("Message received from {0}:", endPoint.ToString());
Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
}
catch (SocketException e)
{
if (e.SocketErrorCode == SocketError.HostUnreachable)
throw new Exception("CLOSED");
throw new Exception("TIME_OUT");
}
Console.WriteLine("Stopping client");
server.Close();
}
示例3: Permit
public void Permit(EndPoint endPoint)
{
if (permited != null)
{
if (permited.ContainsKey(endPoint.ToString()) == false)
permited.Add(endPoint.ToString(), null);
}
}
示例4: addToFileList
private void addToFileList(List<string> files, EndPoint endPoint)
{
string directoryFile = @".\PeerDirectory\" + endPoint.ToString().Split(':')[0] + "_" + files.ElementAt(0) + ".txt"; // The file where we want to save the client/file informaiton
files.RemoveAt(0); // removes port number from beginning of file list
File.WriteAllLines(directoryFile, files); // Write all the data in the list to the file.
// Save the list of files from the client to the directory.
}
示例5: AcceptConnection
public static bool AcceptConnection(EndPoint ipAddress)
{
MaxConnections.AddConnection(ipAddress);
string tempIP = ipAddress.ToString().Split(':')[0];
return (_connections[tempIP] <= _maxConnections);
}
示例6: CreateClient
/// <summary>
/// 创建客户端。
/// </summary>
/// <param name="endPoint">终结点。</param>
/// <returns>传输客户端实例。</returns>
public ITransportClient CreateClient(EndPoint endPoint)
{
var key = endPoint.ToString();
return _clients.GetOrAdd(key, k => new Lazy<ITransportClient>(() =>
{
var messageListener = new MessageListener();
Func<TcpSocketSaeaClient> clientFactory = () =>
{
var client = new TcpSocketSaeaClient((IPEndPoint)endPoint, async (c, data, offset, count) =>
{
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("接收到数据包。");
var transportMessageDecoder = _transportMessageCodecFactory.GetDecoder();
var transportMessageEncoder = _transportMessageCodecFactory.GetEncoder();
var message = transportMessageDecoder.Decode(data.Skip(offset).Take(count).ToArray());
if (_logger.IsEnabled(LogLevel.Information))
_logger.LogInformation("接收到消息:" + message.Id);
await messageListener.OnReceived(new SimpleClientMessageSender(transportMessageEncoder, c), message);
});
client.Connect().Wait();
return client;
};
return new TransportClient(new SimpleClientMessageSender(_transportMessageCodecFactory.GetEncoder(), clientFactory), messageListener, _logger, _serviceExecutor);
})).Value;
}
示例7: IsPermited
public bool IsPermited(EndPoint endPoint)
{
if (permited == null)
return true;
return permited.ContainsKey(endPoint.ToString());
}
示例8: sendAnswer
private static void sendAnswer(EndPoint ep)
{
try
{
string ipStr = ep.ToString().Split(':')[0];
TcpClient client = new TcpClient(ipStr, 9999);
if (client.Connected)
{
Socket s = client.Client;
s.Send(Encoding.ASCII.GetBytes(ipStr));
s.Close();
}
client.Close();
}
catch(Exception ex) { Console.WriteLine("error with {0}\n{1}", ep.ToString().Split(':')[0], ex.ToString()); }
}
示例9: KinectClient
public KinectClient(EndPoint endPoint)
{
Name = "Client_" + i;
IP = endPoint.ToString().Split(':')[0];
Connected = true;
i++;
}
示例10: CreateClient
/// <summary>
/// 创建客户端。
/// </summary>
/// <param name="endPoint">终结点。</param>
/// <returns>传输客户端实例。</returns>
public ITransportClient CreateClient(EndPoint endPoint)
{
var key = endPoint.ToString();
if (_logger.IsEnabled(LogLevel.Debug))
_logger.Debug($"准备为服务端地址:{key}创建客户端。");
return _clients.GetOrAdd(key
, k => new Lazy<ITransportClient>(() =>
{
var messageListener = new MessageListener();
_bootstrap.Handler(new ActionChannelInitializer<ISocketChannel>(c =>
{
var pipeline = c.Pipeline;
pipeline.AddLast(new LengthFieldPrepender(4));
pipeline.AddLast(new LengthFieldBasedFrameDecoder(int.MaxValue, 0, 4, 0, 4));
pipeline.AddLast(new DefaultChannelHandler(messageListener));
}));
var bootstrap = _bootstrap;
var channel = bootstrap.ConnectAsync(endPoint);
var messageSender = new NettyMessageClientSender(channel);
var client = new TransportClient(messageSender, messageListener, _logger, _serializer);
return client;
}
)).Value;
}
示例11: AsyncReader
public AsyncReader(IByteParser parser, byte[] buffer, IAcceptor acceptor, ISocketErrorHandler errorHandler, Socket socket)
{
_parser = parser;
_buffer = buffer;
_acceptor = acceptor;
_errorHandler = errorHandler;
_socket = socket;
_endpoint = socket.RemoteEndPoint;
_log = LogManager.GetLogger(_endpoint.ToString());
}
示例12: AddPlayer
/// <summary>
/// Ensures that a player isn't already in the game and adds them
/// </summary>
/// <param name="playerAddress">IP address of player</param>
/// <param name="name">Name of player</param>
/// <returns>Boolean if the add was successful</returns>
public Boolean AddPlayer( EndPoint playerAddress, string name)
{
if (!AddressLookup.ContainsKey(playerAddress.ToString()))
{
AddressLookup.Add(playerAddress.ToString(), NumberPlayers);
Player p = new Player();
p.Address = playerAddress;
p.PlayerNumber = NumberPlayers;
p.Name = name;
PlayerArray.Add( p);
NumberPlayers++;
PlayersRemaining = NumberPlayers;
return true;
}
else
{
return false;
}
}
示例13: CreateClient
/// <summary>
/// 创建客户端。
/// </summary>
/// <param name="endPoint">终结点。</param>
/// <returns>传输客户端实例。</returns>
public ITransportClient CreateClient(EndPoint endPoint)
{
var config = new TcpSocketSaeaClientConfiguration();
var key = endPoint.ToString();
return _clients.GetOrAdd(key, k => new Lazy<ITransportClient>(() =>
{
var messageListener = new MessageListener();
var client = new TcpSocketSaeaClient((IPEndPoint)endPoint, new SimpleMessageDispatcher(messageListener, _transportMessageCodecFactory, _logger), config);
client.Connect().Wait();
return new TransportClient(new SimpleClientMessageSender(_transportMessageCodecFactory.GetEncoder(), client), messageListener, _logger, _serviceExecutor);
})).Value;
}
示例14: Disconnect
public static void Disconnect(EndPoint ipAddress)
{
string tempIP = ipAddress.ToString().Split(':')[0];
if (_connections.ContainsKey(tempIP))
_connections[tempIP]--;
if ((_connections.ContainsKey(tempIP))
&& (_connections[tempIP] == 0))
{
_connections.Remove(tempIP); //No connections... remove it from the list
}
}
示例15: Format
public static string Format(EndPoint endPoint)
{
var dnsEndPoint = endPoint as DnsEndPoint;
if (dnsEndPoint != null)
{
return string.Concat(
dnsEndPoint.Host,
":",
dnsEndPoint.Port.ToString());
}
return endPoint.ToString();
}