본문 바로가기

전체 글

(86)
C# Multi Thread TcpServer C# Multi Thread TcpServer public class TcpServer { private static TcpServer _instance; public static TcpServer Instance { get { return _instance; } } private TcpListener m_TcpListener; private int _nPort = 13000; private string _sIPAddress; private List m_Clients; private Thread m_ListenThread; public TcpServer() { if (_instance == null) { _instance = this; } this.m_Clients = new List(); } publi..
C# TCPServer with WebSocket C# TCPServer with WebSocket public class TcpServerWS { private static TcpServerWS _instance; public static TcpServerWS Instance { get { return _instance; } } private TcpListener m_TcpListener; private int _nPort = 13000; private string _sIPAddress; private List m_Clients; private Thread m_ListenThread; public TcpServerWS() { this.m_Clients = new List(); } public void ServerStart() { m_ListenThre..
C# UDP C# UDP UDP 메세지 보내기 UdpClient udpClient = new UdpClient("127.0.0.1", 11000); Byte[] sendBytes = Encoding.ASCII.GetBytes("PlayWall1F"); udpClient.Send(sendBytes, sendBytes.Length); udpClient.Close(); UDP 메세지 마지막에 NewLine 붙여서 보내기 UdpClient udpClient = new UdpClient(ip, port); Byte[] sendBytes = Encoding.ASCII.GetBytes(message); byte[] newLine = System.Text.ASCIIEncoding.ASCII.GetBytes(Environment.N..
C# WOL 컴퓨터 원격 온오프 C# WOLC# WOL 컴퓨터 원격 온오프 public class WakeOnLan : UdpClient { public WakeOnLan() : base() { } /// /// 컴퓨터 부팅 하기 /// /// 부팅 할 컴퓨터의 맥어드레스 public void TurnOnPC(string macAddress) { try { macAddress = macAddress.Replace("-", ""); macAddress = macAddress.Replace(":", ""); this.Connect(new System.Net.IPAddress(0xffffffff), 0x2fff); //255.255.255.255 : 12287 if (this.Active) { this.Client.SetSocketOptio..
C# Ping 테스트, 해당 IP 장치 이름 가져오기 C# Ping 테스트, 해당 IP 장치 이름 가져오기 public class PingTest { public static double Do(string ip, int timeout = 5000) { try { var pingSender = new Ping(); var options = new PingOptions(); // Use the default Ttl value which is 128, // but change the fragmentation behavior. options.DontFragment = true; // Create a buffer of 32 bytes of data to be transmitted. const string data = "aaaaaaaaaaaaaaaaaaaaaaaaaa..
C# 네트워크 상 맥어드레스 가져오기 C# 네트워크 상 맥어드레스 가져오기 public class MacAddressHelper { private static List _macIpPairs; public static string GetMacByIp(string ip) { if (_macIpPairs == null) { GetAllMacAddressesAndIppairs(); } int index = _macIpPairs.FindIndex(x => x.IpAddress == ip); if (index >= 0) { return _macIpPairs[index].MacAddress.ToUpper(); } else { return string.Empty; } } private static void GetAllMacAddressesAndIppair..
C# http post header body C# http post header body var cl = new HttpClient(); cl.BaseAddress = new Uri(""); int _TimeoutSec = 90; cl.Timeout = new TimeSpan(0, 0, _TimeoutSec); string _ContentType = "application/x-www-form-urlencoded"; cl.DefaultRequestHeaders.Add(key, value); cl.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(_ContentType)); cl.DefaultRequestHeaders.Add("key", "value"); c..
C# HttpClient RestAPI Post C# HttpClient RestAPI Post 비동기 HttpClient public static string BaseUrl = ""; public static async Task Login(bool isReturnResponseMessage = false) { ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; // 인증 string result = string.Empty; try { string id = ""; string pw = ""; var bytevalue = Encoding.UTF8.GetBytes(id + ":" + pw); var base64value = Convert.ToBase64St..