本文整理汇总了C#中ISocket类的典型用法代码示例。如果您正苦于以下问题:C# ISocket类的具体用法?C# ISocket怎么用?C# ISocket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ISocket类属于命名空间,在下文中一共展示了ISocket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: GetHeaders
public static Task<IEnumerable<KeyValuePair<string, string>>> GetHeaders(ISocket socket)
{
var headers = new MemoryStream ();
return Util.ReadExactly (socket, 10).ContinueWith (t =>
{
t.PropagateExceptions ();
byte[] lenBuffer = t.Result;
int pos = Array.IndexOf (lenBuffer, (byte)':');
var lenString = Encoding.UTF8.GetString (lenBuffer, 0, pos);
var len = int.Parse (lenString) + 1;
pos++;
var alreadyReadLen = lenBuffer.Length - pos;
headers.Write (lenBuffer, pos, alreadyReadLen);
return Util.ReadDataAsync (socket, headers, len - alreadyReadLen);
}).Unwrap ().ContinueWith (t2 =>
{
t2.PropagateExceptions ();
var rv = new List<KeyValuePair<string, string>> ();
var headerPairs = Encoding.UTF8.GetString (headers.ToArray ()).Split ((char)0);
for (var i = 0; i < headerPairs.Length - 1; i += 2)
rv.Add (new KeyValuePair<string, string> (headerPairs[i], headerPairs[i + 1]));
return Util.TaskFromResult ((IEnumerable<KeyValuePair<string, string>>)rv);
}).Unwrap ();
}
开发者ID:kekekeks,项目名称:scgi-sharp,代码行数:31,代码来源:ScgiParser.cs
示例2: CloseSock
public static void CloseSock(ISocket socket, int timeout = 0)
{
if (socket.GetSocket().ProtocolType == ProtocolType.Tcp) socket.GetSocket().Shutdown(SocketShutdown.Both);
if (timeout == 0) socket.Close();
else socket.Close(timeout);
}
开发者ID:jccprj,项目名称:AwesomeSockets,代码行数:7,代码来源:AweSock.cs
示例3: SocketSender
public SocketSender(IFireflyService service, ISocket socket)
{
_service = service;
_socket = socket;
_state = State.Immediate;
_socketEvent = _service.Memory.AllocSocketEvent();
}
开发者ID:virajs,项目名称:firefly,代码行数:7,代码来源:SocketSender.cs
示例4: NodeBase
protected NodeBase(ICluster owner, IPEndPoint endpoint, IFailurePolicy failurePolicy, ISocket socket)
{
this.owner = owner;
this.endpoint = endpoint;
this.socket = socket;
this.failurePolicy = failurePolicy;
this.name = endpoint.ToString();
failLock = new Object();
writeQueue = new ConcurrentQueue<Data>();
readQueue = new Queue<Data>();
mustReconnect = true;
IsAlive = true;
counterEnqueuePerSec = Metrics.Meter("node write enqueue/sec", endpoint.ToString(), Interval.Seconds);
counterDequeuePerSec = Metrics.Meter("node write dequeue/sec", endpoint.ToString(), Interval.Seconds);
counterOpReadPerSec = Metrics.Meter("node op read/sec", endpoint.ToString(), Interval.Seconds);
counterWriteQueue = Metrics.Counter("write queue length", endpoint.ToString());
counterReadQueue = Metrics.Counter("read queue length", endpoint.ToString());
counterWritePerSec = Metrics.Meter("node write/sec", endpoint.ToString(), Interval.Seconds);
counterErrorPerSec = Metrics.Meter("node in error/sec", endpoint.ToString(), Interval.Seconds);
counterItemCount = Metrics.Counter("commands", endpoint.ToString());
gaugeSendSpeed = Metrics.Gauge("send speed", endpoint.ToString());
}
开发者ID:adamhathcock,项目名称:EnyimMemcached2,代码行数:26,代码来源:NodeBase.cs
示例5: StreamProxy
public StreamProxy(ISocket inStream, ISocket outStream, int bufferSize = 16384)
{
Logger.Debug("Setting up Stream Proxy from " + inStream.GetType() + " to " + outStream.GetType() + "(bufsize=" + bufferSize + ")");
_inStream = inStream;
_outStream = outStream;
_bufferSize = bufferSize;
}
开发者ID:gwupe,项目名称:Gwupe,代码行数:7,代码来源:StreamProxy.cs
示例6: EngageWith
public void EngageWith(ISocket socket)
{
Interlocked.Exchange(ref _flushingInProgress, 0);
Interlocked.Exchange(ref _writingOffset, 0);
Interlocked.Exchange(ref _socketException, null);
_asyncSocket.EngageWith(socket);
}
开发者ID:tomeucapo,项目名称:RedisBoost,代码行数:7,代码来源:RedisSender.cs
示例7: Receiver
public Receiver(ISocket socket, Action<string> messageAction, Action closeAction)
{
_socket = socket;
_messageAction = messageAction;
_closeAction = closeAction;
_queue = new Queue<byte>();
}
开发者ID:emiaj,项目名称:Fleck,代码行数:7,代码来源:Receiver.cs
示例8: Connection
public Connection(IServerTrace trace, AppDelegate app, ISocket socket, Action<ISocket> disconnected)
{
_trace = trace;
_app = app;
_socket = socket;
_disconnected = disconnected;
}
开发者ID:friesencr,项目名称:dragonfly,代码行数:7,代码来源:Connection.cs
示例9: ClacksClient
public ClacksClient(ISocket socket) {
if(socket == null) {
throw new ArgumentNullException("socket");
}
_socket = socket;
_receiver = new ResponseReceiver(_socket);
}
开发者ID:MindTouch,项目名称:MindTouch.Clacks,代码行数:7,代码来源:ClacksClient.cs
示例10: OnClientConnect
private void OnClientConnect(ISocket clientSocket)
{
FleckLog.Debug(String.Format("Client connected from {0}:{1}", clientSocket.RemoteIpAddress, clientSocket.RemotePort.ToString()));
ListenForClients();
WebSocketConnection connection = null;
connection = new WebSocketConnection(
clientSocket,
_config,
bytes => RequestParser.Parse(bytes, _scheme),
r => HandlerFactory.BuildHandler(r,
s => connection.OnMessage(s),
connection.Close,
b => connection.OnBinary(b),
b => connection.OnPing(b),
b => connection.OnPong(b)),
s => SubProtocolNegotiator.Negotiate(SupportedSubProtocols, s));
if (IsSecure)
{
FleckLog.Debug("Authenticating Secure Connection");
clientSocket
.Authenticate(Certificate,
connection.StartReceiving,
e => FleckLog.Warn("Failed to Authenticate", e));
}
else
{
connection.StartReceiving();
}
}
开发者ID:vishnumitraha,项目名称:seb-win,代码行数:32,代码来源:WebSocketServer.cs
示例11: KayakContext
/// <summary>
/// Constructs a new KayakContext with the provided `ISocket`, `IKayakServerRequest`, and
/// `IKayakServerResponse` objects.
/// </summary>
public KayakContext(ISocket socket, IKayakServerRequest request, IKayakServerResponse response)
{
Socket = socket;
Request = request;
Response = response;
Items = new Dictionary<object, object>();
}
开发者ID:nithinphilips,项目名称:bbwifimusicsync,代码行数:11,代码来源:KayakContext.cs
示例12: CreateContext
public static KayakContext CreateContext(ISocket socket)
{
var request = new KayakServerRequest(socket);
var response = new KayakServerResponse(socket);
return new KayakContext(socket, request, response);
}
开发者ID:nithinphilips,项目名称:bbwifimusicsync,代码行数:7,代码来源:KayakContext.cs
示例13: BeginRequestInternal
public IEnumerable<object> BeginRequestInternal(ISocket socket)
{
var bufferHeaders = new ContinuationState<LinkedList<ArraySegment<byte>>>(socket.BufferHeaders());
yield return bufferHeaders;
var headerBuffers = bufferHeaders.Result;
Dictionary<string, object> env = new Dictionary<string, object>();
var bodyDataReadWithHeaders = headerBuffers.Last.Value;
headerBuffers.RemoveLast();
var headersString = headerBuffers.GetString();
var reader = new StringReader(headersString);
var requestLine = reader.ReadRequestLine();
var headers = reader.ReadHeaders();
env["Owin.RequestMethod"] = requestLine.Verb;
env["Owin.RequestUri"] = requestLine.RequestUri;
env["Owin.RequestHeaders"] = headers;
env["Owin.BaseUri"] = "";
env["Owin.RemoteEndPoint"] = socket.RemoteEndPoint;
env["Owin.RequestBody"] = CreateReadBody(socket, bodyDataReadWithHeaders);
// TODO provide better values
env["Owin.ServerName"] = "";
env["Owin.ServerPort"] = 0;
env["Owin.UriScheme"] = "http";
yield return env;
}
开发者ID:lovewitty,项目名称:OstrichNet,代码行数:31,代码来源:HttpSupport.cs
示例14: EngageWith
public void EngageWith(ISocket socket)
{
_socket = socket;
_notIoArgs.AcceptSocket = _socket.UnderlyingSocket;
_receiveArgs.AcceptSocket = _socket.UnderlyingSocket;
_sendArgs.AcceptSocket = _socket.UnderlyingSocket;
}
开发者ID:okusnadi,项目名称:RedisBoost,代码行数:7,代码来源:AsyncSocketWrapper.cs
示例15: OnClientConnect
private void OnClientConnect(ISocket clientSocket)
{
FleckLog.Debug("Client Connected");
ListenForClients();
WebSocketConnection connection = null;
connection = new WebSocketConnection(
clientSocket,
_config,
bytes => RequestParser.Parse(bytes, _scheme),
r => HandlerFactory.BuildHandler(r,
s => connection.OnMessage(s),
connection.Close,
b => connection.OnBinary(b)));
if (IsSecure)
{
FleckLog.Debug("Authenticating Secure Connection");
clientSocket
.Authenticate(_x509Certificate,
connection.StartReceiving,
e => FleckLog.Warn("Failed to Authenticate", e));
}
else
{
connection.StartReceiving();
}
}
开发者ID:Chossing,项目名称:EECS-582,代码行数:29,代码来源:WebSocketServer.cs
示例16: SendReceiveAndVerify
public NodeType SendReceiveAndVerify(ISocket socket, TimeSpan timeout)
{
var greetingMessageNegotiator = NodeGreetingMessageNegotiatorFactory.CreateFromSocket(socket);
var tcpSocket = socket as TcpSocket;
var sendReceiveTimeout = new Tuple<int, int>(0, 0);
if (tcpSocket != null)
{
sendReceiveTimeout = new Tuple<int, int>(tcpSocket.TcpClient.SendTimeout,
tcpSocket.TcpClient.ReceiveTimeout);
tcpSocket.TcpClient.SendTimeout = timeout.ToMillisOrZero();
tcpSocket.TcpClient.ReceiveTimeout = timeout.ToMillisOrZero();
}
try
{
greetingMessageNegotiator.WriteGreeting(_greetingMessage);
var readGreeting = greetingMessageNegotiator.VerifyRemoteGreeting(_expectedRemoteNodeTypes);
return readGreeting.NodeType;
}
catch (IOException)
{
throw new TimeoutException("Timeout occurred negotiating after connection had been established");
}
finally
{
if (tcpSocket != null)
{
tcpSocket.TcpClient.SendTimeout = sendReceiveTimeout.Item1;
tcpSocket.TcpClient.ReceiveTimeout = sendReceiveTimeout.Item2;
}
}
}
开发者ID:tleviathan,项目名称:redfoxmq,代码行数:35,代码来源:NodeGreetingMessageVerifier.cs
示例17: SC_LOGIN_RESULT_Handler
public static bool SC_LOGIN_RESULT_Handler(ISocket sock, byte[] buffer)
{
SC_LOGIN_RESULT_Packet packet = PacketHelper.ParsePacketStruct<SC_LOGIN_RESULT_Packet>(buffer);
Int16 readLen = PacketHelper.ParseBodyLen(buffer);
if (readLen < PacketHelper.Size(packet))
{
Console.WriteLine("read length is too small({0})", readLen);
return true; // socket close
}
if (packet.Result == 1)
{
Console.WriteLine("Login success");
Program.loginResult = 1;
Program.m_alldone.Set();
}
else if (packet.Result == 0)
{
Console.WriteLine("Login fail");
Program.loginResult = 0;
Program.m_alldone.Set();
}
else
{
Console.WriteLine("unknown result({0})", packet.Result);
return true;
}
return false;
}
开发者ID:acoross,项目名称:Cs_ChatProgram,代码行数:30,代码来源:SC_PacketHandler.cs
示例18: CreateReadBody
public Func<byte[], int, int, Action<Action<int>, Action<Exception>>> CreateReadBody(
ISocket socket,
ArraySegment<byte> bodyDataReadWithHeaders)
{
return (buffer, offset, count) =>
{
if (bodyDataReadWithHeaders.Count > 0)
{
int bytesRead;
bytesRead = Math.Min(bodyDataReadWithHeaders.Count, count);
Buffer.BlockCopy(bodyDataReadWithHeaders.Array, bodyDataReadWithHeaders.Offset, buffer, offset, bytesRead);
if (bytesRead < bodyDataReadWithHeaders.Count)
bodyDataReadWithHeaders =
new ArraySegment<byte>(
bodyDataReadWithHeaders.Array,
bodyDataReadWithHeaders.Offset + bytesRead,
bodyDataReadWithHeaders.Count - bytesRead);
else
bodyDataReadWithHeaders = default(ArraySegment<byte>);
return (r, e) => r(bytesRead);
}
else if (socket != null)
{
return socket.Read(buffer, offset, count);
}
else
{
return (r, e) => r(0);
}
};
}
开发者ID:purplecow,项目名称:kayak,代码行数:34,代码来源:HttpSupport.cs
示例19: RpcClient
public RpcClient(ISocket socket)
{
if(socket == null) {
throw new ArgumentNullException("socket");
}
_socket = socket;
}
开发者ID:sdether,项目名称:protobuf-socket-rpc,代码行数:7,代码来源:RpcClient.cs
示例20: Connection
public Connection(IFireflyService services, AppDelegate app, ISocket socket, Action<ISocket> disconnected)
{
_services = services;
_app = app;
_socket = socket;
_socketSender = new SocketSender(_services, _socket);
_disconnected = disconnected;
}
开发者ID:ktairov,项目名称:firefly,代码行数:8,代码来源:Connection.cs
注:本文中的ISocket类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论