本文整理汇总了C#中ISocket.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# ISocket.Connect方法的具体用法?C# ISocket.Connect怎么用?C# ISocket.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISocket
的用法示例。
在下文中一共展示了ISocket.Connect方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ProxyThis
private void ProxyThis(ISocket instream, ISocket outstream, AutoResetEvent readyToConnect)
{
Logger.Debug("Starting Proxy from " + instream + " to " + outstream);
int read = 1;
Closed = false;
try
{
var inBuffer = new byte[_bufferSize];
// listen for incoming connection
if (!instream.Connected)
{
readyToConnect.Set();
Logger.Debug("Listening for incoming connections");
instream.ListenOnce();
Logger.Debug("Connected incoming");
}
// connect to outgoing endpoint and start the reverse proxy
if (!outstream.Connected)
{
outstream.Connect();
Logger.Debug("Connected outgoing");
_outRunner.Start();
Logger.Debug("Started Reverse Proxy");
}
while (read > 0)
{
// Read from instream
if (read > 0)
{
try
{
read = instream.Read(inBuffer, _bufferSize);
#if DEBUG
// Logger.Debug("Read " + read + " bytes from " + instream);
#endif
}
catch (Exception ex)
{
Logger.Error("Failed to read data from stream (" + instream + "), closing proxy : " + ex.Message);
break;
}
if (read > 0)
{
try
{
outstream.Send(inBuffer, read);
#if DEBUG
//Logger.Debug("Wrote " + read + " bytes to " + outstream);
#endif
}
catch (Exception ex)
{
Logger.Error("Failed to send data through stream (" + instream + ") , closing proxy : " + ex.Message);
break;
}
}
}
else
{
Logger.Warn("Read no data from (" + instream + "), closing proxy");
}
}
}
catch (Exception ex)
{
Logger.Error("Thread caught exception while processing : " + ex.Message, ex);
}
finally
{
try
{
instream.Close();
}
catch (Exception ex)
{
Logger.Error("Caught Error closing stream (" + instream + ") : " + ex.Message, ex);
}
try
{
outstream.Close();
}
catch (Exception ex)
{
Logger.Error("Caught Error closing stream (" + outstream + ") : " + ex.Message, ex);
}
}
}
示例2: TcpConnectThread
private static void TcpConnectThread(ISocket connectSocket, EndPoint remoteEndpont, Func<ISocket, Exception, Socket> callback)
{
try
{
connectSocket.Connect(remoteEndpont);
}
catch (Exception ex)
{
callback(null, ex);
}
callback(connectSocket, null);
}
示例3: RegisterExternalRoutes
private bool RegisterExternalRoutes(IMessage message, ISocket scaleOutBackend)
{
var shouldHandle = IsExternalRouteRegistration(message);
if (shouldHandle)
{
var payload = message.GetPayload<RegisterExternalMessageRouteMessage>();
var handlerSocketIdentifier = new SocketIdentifier(payload.SocketIdentity);
var uri = new Uri(payload.Uri);
foreach (var registration in payload.MessageContracts)
{
try
{
var messageHandlerIdentifier = new MessageIdentifier(registration.Version, registration.Identity);
externalRoutingTable.AddMessageRoute(messageHandlerIdentifier, handlerSocketIdentifier, uri);
scaleOutBackend.Connect(uri);
}
catch (Exception err)
{
logger.Error(err);
}
}
}
return shouldHandle;
}
示例4: Connect
public void Connect()
{
lock (SyncObject)
{
if (IsConnected())
return;
Close();
try
{
_socket = new SocketAdapter(new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
{
NoDelay = true,
ReceiveTimeout = ReceiveTimeout,
SendTimeout = SendTimeout
});
_socket.Connect(Host, Port);
}
catch (Exception ex)
{
throw new GearmanConnectionException("Could not connect", ex);
}
if (!_socket.Connected)
{
throw new GearmanConnectionException("Socket not connected");
}
_isDead = false;
}
}