本文整理汇总了C#中System.Net.Sockets.TcpListener.SetAddress方法的典型用法代码示例。如果您正苦于以下问题:C# TcpListener.SetAddress方法的具体用法?C# TcpListener.SetAddress怎么用?C# TcpListener.SetAddress使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.TcpListener
的用法示例。
在下文中一共展示了TcpListener.SetAddress方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bind
public bool Bind(String addr)
{
if (m_ctxTerminated)
{
ZError.ErrorNumber = (ErrorNumber.ETERM);
return false;
}
// Process pending commands, if any.
bool brc = ProcessCommands(0, false);
if (!brc)
return false;
// Parse addr_ string.
Uri uri;
try
{
uri = new Uri(addr);
}
catch (Exception e)
{
throw new ArgumentException(addr, e);
}
String protocol = uri.Scheme;
String address = uri.Authority;
String path = uri.AbsolutePath;
if (string.IsNullOrEmpty(address))
address = path;
CheckProtocol(protocol);
if (protocol.Equals("inproc"))
{
Ctx.Endpoint endpoint = new Ctx.Endpoint(this, m_options);
bool rc = RegisterEndpoint(addr, endpoint);
if (rc)
{
// Save last endpoint URI
m_options.LastEndpoint = addr;
}
return rc;
}
if (protocol.Equals("pgm") || protocol.Equals("epgm"))
{
// For convenience's sake, bind can be used interchageable with
// connect for PGM and EPGM transports.
return Connect(addr);
}
// Remaining trasnports require to be run in an I/O thread, so at this
// point we'll choose one.
IOThread ioThread = ChooseIOThread(m_options.Affinity);
if (ioThread == null)
{
ZError.ErrorNumber = (ErrorNumber.EMTHREAD);
return false;
}
if (protocol.Equals("tcp"))
{
TcpListener listener = new TcpListener(
ioThread, this, m_options);
bool rc = listener.SetAddress(address);
if (!rc)
{
listener.Destroy();
EventBindFailed(addr, ZError.ErrorNumber);
//LOG.error("Failed to Bind", ZError.exc());
return false;
}
// Save last endpoint URI
m_options.LastEndpoint = listener.Address;
AddEndpoint(addr, listener);
return true;
}
if (protocol.Equals("ipc"))
{
IpcListener listener = new IpcListener(
ioThread, this, m_options);
bool rc = listener.SetAddress(address);
if (!rc)
{
listener.Destroy();
EventBindFailed(addr, ZError.ErrorNumber);
return false;
}
// Save last endpoint URI
m_options.LastEndpoint = listener.Address;
AddEndpoint(addr, listener);
return true;
}
Debug.Assert(false);
return false;
}