本文整理汇总了C#中ITransport.Send方法的典型用法代码示例。如果您正苦于以下问题:C# ITransport.Send方法的具体用法?C# ITransport.Send怎么用?C# ITransport.Send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ITransport
的用法示例。
在下文中一共展示了ITransport.Send方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BufferedTransport
public BufferedTransport(IEasyGelfLogger logger, ITransport transport)
{
new Thread(() =>
{
var cancellationToken = cancellationTokenSource.Token;
try
{
GelfMessage mesage;
while (buffer.TryTake(out mesage, -1, cancellationToken))
{
try
{
transport.Send(mesage);
}
catch(Exception exception)
{
logger.Error("Cannot send message", exception);
}
}
}
catch
{
GelfMessage message;
while (buffer.TryTake(out message))
{
try
{
transport.Send(message);
}
catch (Exception exception)
{
logger.Error("Cannot send message", exception);
}
}
}
transport.Close();
stopEvent.Set();
}) {IsBackground = true, Name = "EasyGelf Buffered Transport Thread"}.Start();
}
示例2: Start
internal ProtocolHeader Start(string hostname, ITransport transport)
{
ProtocolHeader myHeader = new ProtocolHeader() { Id = 3, Major = 1, Minor = 0, Revision = 0 };
ByteBuffer headerBuffer = new ByteBuffer(
new byte[] { (byte)'A', (byte)'M', (byte)'Q', (byte)'P', myHeader.Id, myHeader.Major, myHeader.Minor, myHeader.Revision },
0,
8,
8);
transport.Send(headerBuffer);
Trace.WriteLine(TraceLevel.Frame, "SEND AMQP {0}", myHeader);
DescribedList command = this.GetStartCommand(hostname);
if (command != null)
{
this.SendCommand(transport, command);
}
return myHeader;
}
示例3: SendCommand
void SendCommand(ITransport transport, DescribedList command)
{
ByteBuffer buffer = new ByteBuffer(Frame.CmdBufferSize, true);
Frame.Encode(buffer, FrameType.Sasl, 0, command);
transport.Send(buffer);
Trace.WriteLine(TraceLevel.Frame, "SEND {0}", command);
}
示例4: ProcessResult
public void ProcessResult(RawMessage message, ITransport transport, ILogger log)
{
transport.Send(message.ReplyTopic, ReplyMessage);
}
示例5: TestSendReceive
private async Task TestSendReceive(ITransport outputTransport, string destinationQueueUrlOrName, ITransport destinationTransport)
{
await WithContext(async (context) => { await outputTransport.Send(destinationQueueUrlOrName, MessageWith("hallo"), context); });
await WithContext(async (context) =>
{
var received = await destinationTransport.Receive(context);
Assert.AreEqual("hallo", GetStringBody(received));
});
}
示例6: OnConnected
private void OnConnected(ITransport transport)
{
try {
LoggingService.LogInfo("Transport {0} connected.", transport);
if (transport.Encryptor != null) {
DiffieHellmanManaged dh = new DiffieHellmanManaged ();
byte[] keyxBytes = dh.CreateKeyExchange ();
transport.Send (dh.CreateKeyExchange (), 0, keyxBytes.Length);
keyxBytes = new byte [transport.Encryptor.KeyExchangeLength];
transport.Receive (keyxBytes, 0, transport.Encryptor.KeyExchangeLength);
keyxBytes = dh.DecryptKeyExchange (keyxBytes);
byte[] keyBytes = new byte[transport.Encryptor.KeySize];
byte[] ivBytes = new byte[transport.Encryptor.IvSize];
Array.Copy (keyxBytes, 0, keyBytes, 0, keyBytes.Length);
Array.Copy (keyxBytes, keyBytes.Length, ivBytes, 0, ivBytes.Length);
transport.Encryptor.SetKey(keyBytes, ivBytes);
}
byte[] connectionType = EndianBitConverter.GetBytes (transport.ConnectionType);
transport.Send (connectionType, 0, connectionType.Length);
byte[] networkId = Common.SHA512 (transport.Network.NetworkName);
transport.Send (networkId, 0, networkId.Length);
// Ready, Steady, GO!
TransportCallback callback = (TransportCallback) connectCallbacks [transport];
connectCallbacks.Remove (transport);
callback (transport);
} catch (Exception ex) {
transport.Disconnect (ex);
RaiseTransportError(transport, ex);
}
}
示例7: Add
internal void Add(ITransport transport, TransportCallback connectCallback)
{
try {
// XXX: This should be negotiated as part of the initial handshake.
transport.Encryptor = new AESTransportEncryptor();
transports.Add (transport);
if (NewTransportAdded != null)
NewTransportAdded (transport);
LoggingService.LogInfo(String.Format ("Transport {0} added", transport.ToString()));
if (transport.Incoming == true) {
if (connectCallback != null)
throw new ArgumentException ("You can only specify a ConnectCallback for outoging connections!");
if (transport.Encryptor != null) {
DiffieHellmanManaged dh = new DiffieHellmanManaged ();
byte[] keyxBytes = new byte[transport.Encryptor.KeyExchangeLength];
transport.Receive (keyxBytes, 0, keyxBytes.Length);
keyxBytes = dh.DecryptKeyExchange (keyxBytes);
byte[] keyBytes = new byte[transport.Encryptor.KeySize];
byte[] ivBytes = new byte[transport.Encryptor.IvSize];
Array.Copy (keyxBytes, 0, keyBytes, 0, keyBytes.Length);
Array.Copy (keyxBytes, keyBytes.Length, ivBytes, 0, ivBytes.Length);
keyxBytes = dh.CreateKeyExchange ();
transport.Send (keyxBytes, 0, keyxBytes.Length);
transport.Encryptor.SetKey(keyBytes, ivBytes);
}
//Receive connection type, which is a ulong (8 bytes)
byte[] responseBuffer = new byte[8];
transport.Receive (responseBuffer, 0, 8);
ulong connectionType = EndianBitConverter.ToUInt64 (responseBuffer, 0);
// Recieve network ID (64 bytes)
responseBuffer = new byte[64];
transport.Receive (responseBuffer, 0, 64);
string networkId = EndianBitConverter.ToString (responseBuffer).Replace ("-", "");
// Match to one of our known networks!
foreach (Network network in Core.Networks) {
if (network.NetworkID == networkId) {
transport.Network = network;
}
}
if (transport.Network == null) {
throw new Exception (String.Format ("Unknown network: {0}.", networkId));
}
transport.ConnectionType = connectionType;
if (connectionType == ConnectionType.NodeConnection) {
LocalNodeConnection connection = new LocalNodeConnection(transport);
transport.Operation = connection;
transport.Network.AddConnection(connection);
connection.Start();
} else if (connectionType == ConnectionType.TransferConnection) {
Core.FileTransferManager.NewIncomingConnection(transport);
} else {
throw new Exception(String.Format("Unknown connection type: {0}.",
connectionType.ToString()));
}
} else {
if (connectCallback == null) {
throw new ArgumentNullException("connectCallback");
}
connectCallbacks.Add (transport, connectCallback);
LoggingService.LogInfo("Transport {0} connecting...", transport);
TransportCallback callback = new TransportCallback (OnConnected);
transport.Connect (callback);
}
} catch (Exception ex) {
transport.Disconnect (ex);
RaiseTransportError(transport, ex);
}
}