本文整理汇总了C#中System.Net.Sockets.NetworkStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# NetworkStream.Flush方法的具体用法?C# NetworkStream.Flush怎么用?C# NetworkStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Sockets.NetworkStream
的用法示例。
在下文中一共展示了NetworkStream.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Start
/// <summary>
/// Start the listener for incoming messages
/// </summary>
public void Start()
{
tcpListener = new TcpListener(System.Net.IPAddress.Any, this.port);
tcpListener.Start();
Console.WriteLine("Server Started") ;
this.IsListening = true;
try
{
while (isListening)
{
Console.WriteLine("Server listening...");
Socket socketForClient = tcpListener.AcceptSocket();
Console.WriteLine("Client connected");
NetworkStream networkStream = new NetworkStream(socketForClient);
BinaryFormatter bf = new BinaryFormatter();
Object message = (RemoteMessage)bf.Deserialize(networkStream);
networkStream.Flush();
interpretMessage((RemoteMessage)message);
socketForClient.Disconnect(true);
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString()) ;
}
}
示例2: Send
//Méthode statique pour l'envoi et la réception
public void Send(Paquet paquet, NetworkStream stream)
{
BinaryFormatter bf = new BinaryFormatter();
bf.Serialize(stream, paquet);
stream.Flush();
}
示例3: Write
public void Write(NetworkStream stream)
{
stream.WriteByte((byte)this.Type);
StreamHelper.WriteDouble(stream, this.Unknown1);
StreamHelper.WriteDouble(stream, this.Unknown2);
StreamHelper.WriteDouble(stream, this.Unknown3);
StreamHelper.WriteFloat(stream, this.Unknown4);
StreamHelper.WriteInt(stream, Unknown5.Count);
int i = (int)this.Unknown1;
int j = (int)this.Unknown2;
int k = (int)this.Unknown3;
sbyte j1;
for (IEnumerator<ChunkPosition> iter = this.Unknown5.GetEnumerator(); iter.MoveNext(); stream.WriteByte(j1))
{
ChunkPosition chunkpos = iter.Current;
int l = chunkpos.X - i;
int i1 = chunkpos.Y - j;
j1 = (sbyte)(chunkpos.Z - k);
stream.WriteByte((byte)l);
stream.WriteByte((byte)i1);
}
stream.Flush();
}
示例4: button2_Click
private void button2_Click(object sender, EventArgs e)
{
try
{
readData = "Connected to Chat Server ...";
msg();
clientSocket.Connect("127.0.0.1", 8888);
serverStream = clientSocket.GetStream();
byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox2.Text + "$");
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
Thread ctThread = new Thread(getMessage);
ctThread.Start();
if(strUser == null)
{
strUser = textBox2.Text;
Registry.SetValue(keyName, "user", strUser);
}
buttonSend.Enabled = true;
}
catch(Exception ex)
{
buttonSend.Enabled = false;
}
}
示例5: Write
public void Write(NetworkStream stream)
{
stream.WriteByte((byte)this.Type);
StreamHelper.WriteString(stream, this.Username);
stream.Flush();
}
示例6: send
private void send(NetworkStream networkStream, Byte[] bufferOut)
{
//------------------------------------------------Send message
networkStream.Write(bufferOut, 0, bufferOut.Length);
networkStream.Flush();
base.ByteSent += bufferOut.Length;
}
示例7: button2_Click
private void button2_Click(object sender, EventArgs e)
{
readData = "Conected to Chat Server ...";
msg();
clientSocket.Connect("127.0.0.1", 8888);
serverStream = clientSocket.GetStream();
byte[] outStream = System.Text.Encoding.ASCII.GetBytes(textBox3.Text + "$");
serverStream.Write(outStream, 0, outStream.Length);
serverStream.Flush();
Thread ctThread = new Thread(getMessage);
ctThread.Start();
}
示例8: SendString
public static void SendString(NetworkStream client, string s)
{
var bytes = Encoding.UTF8.GetBytes(s);
client.Write(BitConverter.GetBytes(bytes.Length), 0, 4);
client.Write(bytes, 0, bytes.Length);
client.Flush();
}
示例9: sendMessage
/**
* Function to send a message to the server
* \param stream - The stream to write to
* \param msg - The message to send
* \return - Retun true on success, false on failure
*/
private bool sendMessage(NetworkStream stream, Message msg)
{
string json = JsonConvert.SerializeObject(msg);
using (MemoryStream mstream = new MemoryStream())
{
using (BinaryWriter writer = new BinaryWriter(mstream))
{
byte[] encodedJson = Encoding.UTF8.GetBytes(json);
writer.Write(hostToBig_i32(encodedJson.Length));
writer.Write(encodedJson);
}
byte[] request = mstream.ToArray();
try
{
stream.Write(request, 0, request.Length);
stream.Flush();
}
catch(SocketException ex)
{
Message emsg = new Message("error_socket", null);
emsg.AddParameter("error_code", ex.ErrorCode);
emsg.AddParameter("message", ex.Message);
recvq.Enqueue(emsg);
return false;
}
}
return true;
}
示例10: send
public virtual void send(NetworkStream ns)
{
if (data == null) {
getBytes ();
}
ns.Write (data, 0, data.Length);
ns.Flush ();
}
示例11: Write
public void Write(NetworkStream stream)
{
stream.WriteByte((byte)this.Type);
stream.WriteByte((OnGround ? (byte)1 : (byte)0));
stream.Flush();
}
示例12: Write
public void Write(NetworkStream stream)
{
stream.WriteByte((byte)this.Type);
stream.WriteByte(this.WindowId);
stream.Flush();
}
示例13: Write
public void Write(NetworkStream stream)
{
stream.WriteByte((byte)this.Type);
StreamHelper.WriteShort(stream, this.PlayerHealth);
stream.Flush();
}
示例14: Write
public void Write(NetworkStream stream)
{
stream.WriteByte((byte)this.Type);
StreamHelper.WriteInt(stream, this.EntityID);
stream.Flush();
}
示例15: AsyncProcessResponse
public void AsyncProcessResponse (IServerResponseChannelSinkStack sinkStack, object state,
IMessage msg, ITransportHeaders headers, Stream responseStream)
{
ClientConnection connection = (ClientConnection)state;
NetworkStream stream = new NetworkStream (connection.Client);
UnixMessageIO.SendMessageStream (stream, responseStream, headers, connection.Buffer);
stream.Flush ();
stream.Close ();
}