Skip to content

Instantly share code, notes, and snippets.

@rustinlee
Created March 20, 2017 21:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rustinlee/ed6c2fb87389e906fc12644e35559dbe to your computer and use it in GitHub Desktop.
Save rustinlee/ed6c2fb87389e906fc12644e35559dbe to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Net.Sockets;
using System.IO;
using System.IO.Pipes;
using System.Text;
public class IPCTester : MonoBehaviour {
NamedPipeClientStream clientStream;
StreamWriter writer;
StreamReader reader;
void Start() {
clientStream = new NamedPipeClientStream("tmp-app.normal");
clientStream.Connect();
writer = new StreamWriter(clientStream);
reader = new StreamReader(clientStream);
}
void Update() {
}
void Ping() {
string pingString = "{ \"type\": \"pong\", \"data\": { \"status\": \"ok\" }\r\n";
byte[] buffer = Encoding.UTF8.GetBytes(pingString);
clientStream.WaitForPipeDrain();
writer.Write(pingString);
writer.Flush();
}
private void OnGUI() {
if (GUI.Button(new Rect(10, 10, 150, 100), "Ping"))
Ping();
}
private void OnApplicationQuit() {
clientStream.Dispose();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment