'C#' 카테고리의 다른 글
| C#에서의 상속관련 (0) | 2008.11.20 | 
|---|---|
| C#에 대한 문서 (0) | 2008.06.05 | 
| GUI방식으로 구성한 EchoClient (0) | 2006.05.30 | 
| 간단한 Class 테스트 (0) | 2006.05.29 | 
| .NET 기반의 Socket클래스를 이용한 Echo Client 프로그램 (0) | 2006.05.29 | 
| C#에서의 상속관련 (0) | 2008.11.20 | 
|---|---|
| C#에 대한 문서 (0) | 2008.06.05 | 
| GUI방식으로 구성한 EchoClient (0) | 2006.05.30 | 
| 간단한 Class 테스트 (0) | 2006.05.29 | 
| .NET 기반의 Socket클래스를 이용한 Echo Client 프로그램 (0) | 2006.05.29 | 
| 마소에서 제공하는 C# Sample 파일 (0) | 2009.08.28 | 
|---|---|
| C#에 대한 문서 (0) | 2008.06.05 | 
| GUI방식으로 구성한 EchoClient (0) | 2006.05.30 | 
| 간단한 Class 테스트 (0) | 2006.05.29 | 
| .NET 기반의 Socket클래스를 이용한 Echo Client 프로그램 (0) | 2006.05.29 | 
마소에서 제공해주는 C#에 대한 공짜 문서이다.
아래의 주소에서 받으면 된다.
http://www.microsoft.com/korea/msdn/vbrun/staythepath/additionalresources/InsideCSharp/default.aspx
		
| 마소에서 제공하는 C# Sample 파일 (0) | 2009.08.28 | 
|---|---|
| C#에서의 상속관련 (0) | 2008.11.20 | 
| GUI방식으로 구성한 EchoClient (0) | 2006.05.30 | 
| 간단한 Class 테스트 (0) | 2006.05.29 | 
| .NET 기반의 Socket클래스를 이용한 Echo Client 프로그램 (0) | 2006.05.29 | 
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Net.Sockets;
namespace FormsSocket
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            if (textBox1.Text.Length < 1)
            {
                MessageBox.Show("전송할 메시지가 없습니다.");
                return;
            }
            MsgSend(textBox1.Text);
        }
        public void MsgSend(string Msg)
        {
            String server = "192.168.0.60";
            byte[] byteBuffer = Encoding.Unicode.GetBytes(Msg);
            int servPort = 7;
            TcpClient client = null;
            NetworkStream netStream = null;
            try
            {
                client = new TcpClient(server, servPort);
                IngMsg.Text = "Connected to server ... Sending echo string";
                netStream = client.GetStream();
                netStream.Write(byteBuffer, 0, byteBuffer.Length);
                IngMsg.Text = "Send " + byteBuffer.Length + " bytes to server...";
                int totalBytesRcvd = 0;
                int bytesRcvd = 0;
                while (totalBytesRcvd < byteBuffer.Length)
                {
                    if ((bytesRcvd = netStream.Read(byteBuffer, totalBytesRcvd,
                    byteBuffer.Length - totalBytesRcvd)) == 0)
                    {
                        IngMsg.Text = "Connection closed prematurely.";
                        break;
                    }
                    totalBytesRcvd += bytesRcvd;
                }
                // textBox2.Text = "Received " + totalBytesRcvd + " bytes from server: " + 
                textBox2.Text = Encoding.Unicode.GetString(byteBuffer, 0, totalBytesRcvd);
            } catch (Exception e) {
                IngMsg.Text = e.Message;
            } finally {
                netStream.Close();
                client.Close();
            }
        }
        private void Form1_Load(object sender, EventArgs e)
        {
            IngMsg.Text = "";
            if (textBox1.CanFocus)
            {
                textBox1.Focus();
            }
        }
    }
               
}| C#에서의 상속관련 (0) | 2008.11.20 | 
|---|---|
| C#에 대한 문서 (0) | 2008.06.05 | 
| 간단한 Class 테스트 (0) | 2006.05.29 | 
| .NET 기반의 Socket클래스를 이용한 Echo Client 프로그램 (0) | 2006.05.29 | 
| TcpEchoServer 프로그램 (0) | 2006.05.28 | 
using System;
public class tp {
    public tp() {
        Console.WriteLine("tp Class Start... ");
    }
    public void me(int i, string str) {
        Console.WriteLine("i Value : " + i + " String Value : " + str);
    }
    ~tp() {
        Console.WriteLine("tp Class Close... ");
    }
}
public class nano {
    public static void Main() {
        tp ko = new tp();
        ko.me(10,"Test");
    }
}| C#에 대한 문서 (0) | 2008.06.05 | 
|---|---|
| GUI방식으로 구성한 EchoClient (0) | 2006.05.30 | 
| .NET 기반의 Socket클래스를 이용한 Echo Client 프로그램 (0) | 2006.05.29 | 
| TcpEchoServer 프로그램 (0) | 2006.05.28 | 
| 직접 코드로 입력한 간단한 C# 프로그램 (0) | 2006.05.28 | 
// --------------------------
// TcpEchoClientSocket.cs
// --------------------------
using System;
using System.Text;
using System.IO;
using System.Net.Sockets;
using System.Net;
class TcpEchoClientSocket {
    static void Main(string[] args) {
        if ((args.Length < 2) || (args.Length > 3)) { // 파라미터 갯수 확인
            throw new ArgumentException("Parameters: <Sever> <Word> [<Port>]");
        }
        String server = args[0];   // 호스트명 또는 IP
        // 입력된 String 객체를 byte로 변환
        byte[] byteBuffer = Encoding.Unicode.GetBytes(args[1]);
        // Port입력하면 값으로 없으면 Default 7로
        int servPort = (args.Length == 3) ? Int32.Parse(args[2]) : 7;
        Socket sock = null;
        try {
            // TCP socket 인스턴트 생성
            sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream,
                                ProtocolType.Tcp);
            // 서버 IPEndPoint 인스턴스 생성
            // Resolve() 메소드가 한개 이상의 IP를 반환한다.
            IPEndPoint serverEndPoint = new IPEndPoint(Dns.GetHostEntry(server).AddressList[0],
                                    servPort);
            // 서버의 해당 포트에 소켓을 연결한다.
            sock.Connect(serverEndPoint);
            Console.WriteLine("Connect to Server ... sending echo string");
            // 인코딩된 스트링을 서버로 전송
            sock.Send(byteBuffer, 0, byteBuffer.Length, SocketFlags.None);
            Console.WriteLine("Sent {0} bytes to server...", byteBuffer.Length);
            int totalBytesRcvd = 0;
            int bytesRcvd = 0;
            // 서버로부터 스트링을 다시 읽는다.
            while (totalBytesRcvd < byteBuffer.Length) {
                if ((bytesRcvd = sock.Receive(byteBuffer, totalBytesRcvd,
                        byteBuffer.Length - totalBytesRcvd, SocketFlags.None)) == 0) {
                    Console.WriteLine("Connection closed prematurely.");
                    break;
                }
                totalBytesRcvd += bytesRcvd;
            }
            Console.WriteLine("Received {0} bytes from server: {1}", totalBytesRcvd,
                    Encoding.Unicode.GetString(byteBuffer, 0, totalBytesRcvd) );
        } catch (Exception e) {
            Console.WriteLine(e.Message);
        } finally {
            sock.Close();
        }
    }
}| GUI방식으로 구성한 EchoClient (0) | 2006.05.30 | 
|---|---|
| 간단한 Class 테스트 (0) | 2006.05.29 | 
| TcpEchoServer 프로그램 (0) | 2006.05.28 | 
| 직접 코드로 입력한 간단한 C# 프로그램 (0) | 2006.05.28 | 
| TcpEchoClient 프로그램 (0) | 2006.05.26 | 
using System;
using System.Net;
using System.Net.Sockets;
class TcpEchoServer {
    private const int BUFSIZE = 32;   // 수신 버퍼의 크기
    static void Main(string[] args) {
        if (args.Length > 1) // 파라미터 개수 확인
            throw new ArgumentException("Parameters: [<port>]");
        int servPort = (args.Length == 1) ? Int32.Parse(args[0]): 7;
        TcpListener listener = null;
        try {
            // 클라이언트의 연결 요청을 수락할 TcpListener 인스턴스를 생성
            listener = new TcpListener(IPAddress.Any, servPort);
            listener.Start();
        } catch (SocketException se) {
            Console.WriteLine(se.ErrorCode + ": " + se.Message);
            Environment.Exit(se.ErrorCode);
        }
        byte[] rcvBuffer = new byte[BUFSIZE];    // 수신 버퍼
        int bytesRcvd;                          // 현재까지 수신된 바이트 수
        for (;;) {
            TcpClient client = null;
            NetworkStream netStream = null;
            try {
                client = listener.AcceptTcpClient(); //클라이언트 연결 요청을 수락
                netStream = client.GetStream();
                Console.Write("Handling client - ");
                // 클라이언트가 0의 값을 전송하여 연결을 종료할 때까지 계속 수신
                int totalBytesEchoed = 0;
                while ((bytesRcvd = netStream.Read(rcvBuffer, 0, rcvBuffer.Length)) > 0) {
                    netStream.Write(rcvBuffer, 0, bytesRcvd);
                    totalBytesEchoed += bytesRcvd;
                }
                Console.WriteLine("echoed {0} bytes.", totalBytesEchoed);
                // 스트림과 소켓을 종료하여 이 클라이언트와의 연결을 종료
                netStream.Close();
                client.Close();
            } catch (Exception e) {
                Console.WriteLine(e.Message);
                netStream.Close();
            }
        }
    }
}| 간단한 Class 테스트 (0) | 2006.05.29 | 
|---|---|
| .NET 기반의 Socket클래스를 이용한 Echo Client 프로그램 (0) | 2006.05.29 | 
| 직접 코드로 입력한 간단한 C# 프로그램 (0) | 2006.05.28 | 
| TcpEchoClient 프로그램 (0) | 2006.05.26 | 
| 호스트 정보를 반환하는 프로그램 (0) | 2006.05.26 | 
// -----------------------------------
// FirstWinFormsProgram.cs
// -----------------------------------
using System.Windows.Forms;
class FirstWinFormsProgram
{
    public static void Main()
    {
        Application.Run(new Form());
    }
}실행 결과| .NET 기반의 Socket클래스를 이용한 Echo Client 프로그램 (0) | 2006.05.29 | 
|---|---|
| TcpEchoServer 프로그램 (0) | 2006.05.28 | 
| TcpEchoClient 프로그램 (0) | 2006.05.26 | 
| 호스트 정보를 반환하는 프로그램 (0) | 2006.05.26 | 
| 마소의 강좌 (0) | 2006.05.18 |