본문 바로가기

C#/Network

(12)
C# Http Post File Upload C# Http Post File Upload private async void Button_Click(object sender, RoutedEventArgs e) { OpenFileDialog dlg = new OpenFileDialog(); dlg.Multiselect = true; if (dlg.ShowDialog() == true) { var result = await Upload(new List(dlg.SafeFileNames), new List(dlg.FileNames)); MessageBox.Show(result ? "성공" : "실패"); } } private async Task Upload(List fileNames, List filePaths) { try { var url = "http:..
C# TCP Client C# TCP Client class CTcpClient { TcpClient client; NetworkStream stream; private Thread m_ListenThread; string serverIP; string tvID; public delegate void OnMessageDele(string message); public event OnMessageDele OnMessage; public CTcpClient() { } public void Connect(string serverIP, string tvID) { this.serverIP = serverIP; this.tvID = tvID; m_ListenThread = new Thread(ConnectTCP); m_ListenThrea..
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..