本文整理汇总了C#中NetworkStream.BeginWrite方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkStream.BeginWrite方法的具体用法?C# NetworkStream.BeginWrite怎么用?C# NetworkStream.BeginWrite使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkStream
的用法示例。
在下文中一共展示了NetworkStream.BeginWrite方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendPacket
public void SendPacket(GSASendPacket packet)
{
packet._Client = this;
if (!GSOpcode.Send.ContainsKey(packet.GetType()))
{
Log.Warn("UNKNOWN GS packet opcode: {0}", packet.GetType().Name);
return;
}
try
{
packet.WriteH(GSOpcode.Send[packet.GetType()]); // opcode
packet.WriteH(0); // packet len
packet.Write();
byte[] Data = packet.ToByteArray();
BitConverter.GetBytes((short)(Data.Length - 4)).CopyTo(Data, 2);
//if(Configuration.Setting.Debug) Log.Debug("Send: {0}", Data.FormatHex());
_stream = _client.GetStream();
_stream.BeginWrite(Data, 0, Data.Length, new AsyncCallback(WriteCallback), (object)null);
}
catch (Exception ex)
{
Log.Warn("Can't send GS packet: {0}", GetType().Name);
Log.WarnException("GSASendPacket", ex);
return;
}
}
示例2: Send
public void Send(NetBitStream bts, Socket peer)
{
NetworkStream ns;
lock (peer)
{
ns = new NetworkStream(peer);
}
if (ns.CanWrite)
{
try
{
ns.BeginWrite(bts.BYTES, 0, bts.Length, new System.AsyncCallback(SendCallback), ns);
}
catch (System.Exception)
{
PushPacket((ushort)MessageIdentifiers.ID.CONNECTION_LOST, "", peer);
}
}
}
示例3: Send
// 发送消息
public void Send(NetBitStream bts)
{
if (!_socket.Connected)
return;
NetworkStream ns;
lock (_socket)
{
ns = new NetworkStream(_socket);
}
if (ns.CanWrite)
{
try
{
ns.BeginWrite(bts.BYTES, 0, bts.Length, new System.AsyncCallback(SendCallback), ns);
}
catch (System.Exception)
{
PushPacket((ushort)MessageIdentifiers.ID.CONNECTION_LOST, "");
Disconnect(0);
}
}
}
示例4: OnConnectionReady
//.........这里部分代码省略.........
readBuffer = new byte[BUFFER_SIZE];
sslStream.BeginRead(readBuffer, 0, readBuffer.Length, new AsyncCallback(OnReceivedData), socketStream);
}
}
else
{
if (socketStream != null && socketStream.CanRead)
{
readBuffer = new byte[BUFFER_SIZE];
socketStream.BeginRead(readBuffer, 0, readBuffer.Length, new AsyncCallback(OnReceivedData), socketStream);
}
}
this.serverSetting.ConnectedTime = DateTime.Now;
RefreshServerTree(this);
if (serverSetting.UseProxy)
{
//socks v5 code
byte[] d = new byte[256];
ushort nIndex = 0;
d[nIndex++] = 0x05;
if (serverSetting.ProxyUser.Length > 0)
{
d[nIndex++] = 0x02;
d[nIndex++] = 0x00;
d[nIndex++] = 0x02;
}
else
{
d[nIndex++] = 0x01;
d[nIndex++] = 0x00;
}
try
{
socketStream.BeginWrite(d, 0, nIndex, new AsyncCallback(OnSendData), socketStream);
if (ServerMessage != null)
ServerMessage(this, "Socks 5 Connection Established with " + serverSetting.ProxyIP);
}
catch (SocketException)
{
System.Diagnostics.Debug.WriteLine("Error Sending Proxy Data");
}
catch (Exception)
{
System.Diagnostics.Debug.WriteLine("proxy exception");
}
}
else
{
ServerPreConnect(this);
if (serverSetting.Password != null && serverSetting.Password.Length > 0)
SendData("PASS " + serverSetting.Password);
if (serverSetting.UseBNC == true && serverSetting.BNCPass != null && serverSetting.BNCPass.Length > 0)
SendData("PASS " + serverSetting.BNCPass);
//send the USER / NICK stuff
SendData("NICK " + serverSetting.NickName);
if (serverSetting.UseBNC == true && serverSetting.BNCUser != null && serverSetting.BNCUser.Length > 0)
SendData("USER " + serverSetting.BNCUser + " \"localhost\" \"" + serverSetting.BNCIP + "\" :" + serverSetting.FullName);
else
SendData("USER " + serverSetting.IdentName + " \"localhost\" \"" + serverSetting.ServerName + "\" :" + serverSetting.FullName);
whichAddressinList = whichAddressCurrent;
if (serverSetting.UseBNC == true)
this.fullyConnected = true;
this.pongTimer.Start();
}
}
catch (SocketException se)
{
System.Diagnostics.Debug.WriteLine("CODE:" + se.SocketErrorCode);
System.Diagnostics.Debug.WriteLine("ST:"+ se.StackTrace);
if (ServerError != null)
ServerError(this, "Socket Exception Error:" + se.Message.ToString() + ":" + se.ErrorCode, false);
disconnectError = true;
ForceDisconnect();
}
catch (Exception e)
{
if (ServerError != null)
ServerError(this, "Exception Error:" + serverSetting.UseBNC + ":" + e.Message.ToString(), false);
disconnectError = true;
ForceDisconnect();
}
}
示例5: Send
public void Send(byte[] bytes)
{
_stream = _client.GetStream();
_stream.BeginWrite(bytes, 0, bytes.Length, WriteCallback, null);
}
示例6: Send
public void Send(byte[] data, AsyncCallback sentCallback)
{
stream = client.GetStream();
data = AppendLengthByte(data);
stream.BeginWrite(data, 0, data.Length, sentCallback, stream);
}
示例7: send_motor_serial
private void send_motor_serial(NetworkStream clientStream)
{
MotorSerial = CLNUIDevice.GetMotorSerial(motor);
System.Text.UTF8Encoding encoding = new System.Text.UTF8Encoding();
clientStream.BeginWrite(encoding.GetBytes(MotorSerial), 0, MotorSerial.Length, null, null);
Console.WriteLine(encoding.GetBytes(MotorSerial).Length);
}
示例8: sendNetMessage
/// <summary>
/// Envia un mensaje a la red mediante esta maquina remota
/// </summary>
/// <param name="netMessage">el mensaje a enviar</param>
/// <param name="timeOutWriteTCP">el tiempo maximo de espera para el envio</param>
public void sendNetMessage(NetMessage netMessage, Int32 timeOutWriteTCP)
{
lock (sendTCPLock)
{
Fails++;
senderStream = new NetworkStream(TcpClient.Client, false);
try
{
//senderStream.WriteTimeout = timeOutWriteTCP;
byte[] lenght = BitConverter.GetBytes(netMessage.getSize());
byte[] netByteMessage = new byte[4 + netMessage.getSize()];
IAsyncResult result = senderStream.BeginWrite(lenght, 0, 4, null, null);
bool success = result.AsyncWaitHandle.WaitOne(timeOutWriteTCP, false);
if (!success)
{
throw new Exception("TCP: intento de conexión ha tardado demasiado");
}
else
{
senderStream.EndWrite(result);
}
result = senderStream.BeginWrite(netMessage.Body, 0, netMessage.getSize(), null, null);
success = result.AsyncWaitHandle.WaitOne(timeOutWriteTCP, false);
if (!success)
{
throw new Exception("TCP: intento de conexión ha tardado demasiado");
}
else
{
senderStream.EndWrite(result);
}
senderStream.Close();
Fails = 0;
}
catch (ThreadAbortException e)
{
try
{
senderStream.Close();
}
catch (Exception)
{
}
throw e;
}
catch (Exception)
{
try
{
senderStream.Close();
}
catch (Exception)
{
}
throw;
}
}
}
示例9: AsyncWrite
public void AsyncWrite ()
{
message = "AsyncWrite";
reset.Reset ();
NetworkStream ns = new NetworkStream (socket, false);
byte[] get = Encoding.ASCII.GetBytes ("GET / HTTP/1.0\n\n");
IAsyncResult r = ns.BeginWrite (get, 0, get.Length, new AsyncCallback (WriteCallback), ns);
Assert.IsNotNull (r, "IAsyncResult");
if (!reset.WaitOne (timeout, true))
Assert.Ignore ("Timeout");
Assert.IsNull (message, message);
ns.Close ();
}
示例10: EnviarComando
public void EnviarComando(string comando)
{
try {
//sock.SendTimeout = 3000;
//sock.ReceiveTimeout = 3000;
//For iso-8859-1, use Encoding.GetEncoding("iso-8859-1");
// For ASCII CP437, use Encoding.GetEncoding(437)
Encoding enc = Encoding.GetEncoding (437);//*********
ns = new NetworkStream (sock);
Console.WriteLine ("Debug: Comando: " + comando);
//byte[] toSend = Encoding.ASCII.GetBytes(comando);
byte[] toSend = enc.GetBytes (comando);//**********
ns.BeginWrite (toSend, 0, toSend.Length, OnWriteComplete, null);
ns.Flush ();
} catch (Exception e) {
Console.WriteLine (e);
}
}