'전체'에 해당되는 글 162

  1. 2010/05/30 Noonipoony 워크래프트 3 화면 1920 * 1080 해상도 설정 (0)
  2. 2010/02/27 Noonipoony Non-blocking Sockets (A Chat Program) (0)
  3. 2010/01/06 Noonipoony C# 스트림라이터로 소켓 통신 (0)
  4. 2010/01/05 Noonipoony C# 다른 스레드에서 Form UI 접근시 invoke (0)
  5. 2010/01/05 Noonipoony C# Dictionary 키 나열하기 (0)

 

           

 

아래 영문처럼 레지스트리를 수정하면 되지만

첨부파일로 수정된 레지스트리를 올렸습니다.

Try doing the following:
1) Make sure the resolution you want to run is supported by your graphics drivers.
If you can select a resolution in your Operating System, then it is supported.

2) Backup your registry, in case something goes wrong.
START > Run > regedit > file > export

3) Change Warcraft 3's resolution manually.
START > run > regedit

While in the Windows Registry Editor (regedit), locate:
HKEY_CURRENT_USER > Software > Blizzard Entertainment > Warcraft III > Video

4) Make below change in decimal format:
(Right click > Change > select "decimal" > fill in new value)
reswidth = 1600
resheight = 900

Replace width & height with whatever resolution you wanna play in, examples:
852x480 16:9 Widescreen
1280x720 16:9 Widescreen
1365x768 16:9 Widescreen
1440x900 16:10 Widescreen
1680x1050 16:10 Widescreen
1920x1200 16:10 Widescreen
320x240 4:3 Aspect ratio
2048x1535 4:3 Aspect ratio

Non-blocking Sockets (A Chat Program)

분류없음 | 2010/02/27 20:03 | Noonipoony

 

           

 

Non-blocking Sockets (A Chat Program)

by: craigrs84

This is a tutorial to explain the use of nonblocking sockets. Non-blocking sockets are the opposite of blocking sockets, and non-blocking sockets do not stop code execution to await incoming data. Non- blocking sockets are more powerful than blocking sockets, but they are also more difficult. I have noticed an advantage to using the Socket class over the TcpListener or TcpClient classes. The TcpListener and TcpClient classes only allow one connection per port number. With the Socket class, you can have as many clients connected to a port as you would like.

This program uses primarily the Socket class. The class TcpSock was built around the Socket class to add ease and functionality.

To start the program you must initialize the Server socket. As you can see, the statement "Server.blocking = false" tells the socket not to block. After initializing the Server socket and binding it to an IP address and port number, the socket is ready to Listen. Now comes the main loop. The first thing we need to check for are incoming connections. Use the Poll method along with the SelectRead argument to do this. When this returns true, we know there is a client trying to connect. So the next thing to do is Accept the connection.

After we have accepted a connection, we can send and receive data. To send the data we simply use the Send method. Receiving data is the hard part. First, we again use the Poll method to check for data available to read. If it returns true, then we call the Recv method, which receives a chunk of data. Telnet does not echo the data unless specifically set to do so, so we will echo the data for telnet. Next we check to see if the person pressed enter... This is this critical part, because we need to know when they have entered a complete line of text, not just a few characters. Once we know they pressed enter, we can send the data to all the other clients using a for loop and the Send method. It's pretty straight- forward.

Lastly, we must close the socket if they disconnect. We already have the information we need. When we Polled the Socket, it returns the number of bytes received. If the number of bytes received = 0, then the Client closed his end of the connection. Now we close our end with the Shutdown and Close methods. Finally, we remove the instance of the TcpSock class from Client, our dynamic array.

This chat program is just a very simple example. If you were ambitious you could add names, commands, and adminstrators.
using System;
using System.Collections;
using System.Net;
using System.Net.Sockets;
using System.Text;

namespace TcpSock
{
class TcpSock
{
int    tcpIndx = 0;
int    tcpByte = 0;
byte[] tcpRecv = new byte[1024];

////////////////////////////////////////
public Socket tcpSock;
////////////////////////////////////////

public int Recv  (ref string tcpRead)
{
    tcpByte = tcpSock.Available;
    if (tcpByte > tcpRecv.Length - tcpIndx)
        tcpByte = tcpRecv.Length - tcpIndx;

    tcpByte = tcpSock.Receive(tcpRecv, tcpIndx, tcpByte, 
        SocketFlags.Partial);
    tcpRead = Encoding.ASCII.GetString
        (tcpRecv, tcpIndx, tcpByte);
    tcpIndx+= tcpByte;
    return    tcpRead.Length;
}

public int RecvLn(ref string tcpRead)
{
    tcpRead = Encoding.ASCII.GetString
        (tcpRecv, 0, tcpIndx);
    tcpIndx = 0;
    return    tcpRead.Length;
}

public int Send  (string tcpWrite)
{
    return tcpSock.Send(Encoding.ASCII.GetBytes(tcpWrite));
}

public int SendLn(string tcpWrite)
{
    return tcpSock.Send(Encoding.ASCII.GetBytes(tcpWrite + "\r\n"));
}
}


class Tcp
{
[STAThread]
static void Main()
{
    ////////////////////////////////////////////////////////////////////////////////////////////
    ///class IPHostEntry : Stores information about the Host and is required 
    ///for IPEndPoint.
    ///class IPEndPoint  : Stores information about the Host IP Address and 
    ///the Port number.
    ///class TcpSock     : Invokes the constructor and creates an instance.
    ///class ArrayList   : Stores a dynamic array of Client TcpSock objects.

    IPHostEntry Iphe   = Dns.Resolve   (Dns.GetHostName());
    IPEndPoint  Ipep   = new IPEndPoint(Iphe.AddressList[0], 4444);
    Socket      Server = new Socket    (Ipep.Address.AddressFamily, 
    SocketType.Stream, ProtocolType.Tcp);

    ////////////////////////////////////////////////////////////////////////////////////////////
    ///Initialize
    ///Capacity : Maximux number of clients able to connect.
    ///Blocking : Determines if the Server TcpSock will stop code execution 
    ///to receive data from the Client TcpSock.
    ///Bind     : Binds the Server TcpSock to the Host IP Address and the Port Number.
    ///Listen   : Begin listening to the Port; it is now ready to accept connections.

    ArrayList Client = new ArrayList ();
    string    rln    = null;

    Client.Capacity =   256;
    Server.Blocking = false;
    Server.Bind  (Ipep);
    Server.Listen( 32 );

    Console.WriteLine("{0}: listening to port {1}", Dns.GetHostName(), 
        Ipep.Port);

    ////////////////////////////////////////////////////////////////////////////////////////////
    ///Main loop
    ///1. Poll the Server TcpSock; if true then accept the new connection.
    ///2. Poll the Client TcpSock; if true then receive data from Clients.

    while (true)
    {
        //Accept
        if (Server.Poll(0, SelectMode.SelectRead))
        {
            int i = Client.Add(new TcpSock());
            ((TcpSock)Client[i]).tcpSock = Server.Accept ();
            ((TcpSock)Client[i]).SendLn("Welcome.");
            Console.WriteLine("Client {0} connected.", i  );
        }

        for (int i = 0; i < Client.Count; i++)
        {
            //check for incoming data
            if (((TcpSock)Client[i]).tcpSock.Poll(0, SelectMode.SelectRead))
            {
                //receive incoming data
                if (((TcpSock)Client[i]).Recv(ref rln) > 0)
                {
                    //echo incoming data
                    ((TcpSock)Client[i]).Send(rln);

                    //check for new line
                    if (rln == "\r\n")
                    {
                       ///receive line
                     ((TcpSock)Client[i]).RecvLn(ref rln);

                     //send the line to all clients
                     for (int y = 0; y < Client.Count; y++)
                        if (y != i)
                        ((TcpSock)Client[y]).Send(i.ToString() + ": " + rln);

                         Console.Write("{0}: {1}", i, rln);
                     }
                }
                    //recv returned <= 0; close the socket
                else
                {
                    ((TcpSock)Client[i]).tcpSock.Shutdown(SocketShutdown.Both);
                    ((TcpSock)Client[i]).tcpSock.Close();
                    Client.RemoveAt (i);
                    Console.WriteLine("Client {0} disconnected.", i);
                }
            }
        }
    }
}
}
}

 

           

 

Introduction :

The Program Socket Programming is used a starter for those who wants to write C# Codes using Net Sockets. It lets you to use Socket Connections with other Systems.

The Server Waits for the Connection and gives a Warm Welcome Message to the User Or the Client.

Tools/API Information :

This Programme it Written using Net.Socket and no extra Feature is used. This is written with the Aim that anyone should understand the Usage of Sockets and NetWorks and to show that C# has got great Support for NetWorking.

Benefit :

There are lots of codes still I am sending this because of its Simplicity and you can use write this Code with just a NotePad/TextPad/Editor.

Server Side Code:

using System;
using System.Net.Sockets;
public class AsynchIOServer
{
public static void Main()
{
TCPListener tcpListener =
new TCPListener(10);
tcpListener.Start();
Socket socketForClient = tcpListener.Accept();
if (socketForClient.Connected)
{
Console.WriteLine("Client connected");
NetworkStream networkStream =
new NetworkStream(socketForClient);
System.IO.StreamWriter streamWriter =
new System.IO.StreamWriter(networkStream);
System.IO.StreamReader streamReader =
new System.IO.StreamReader(networkStream);
string theString = "Sending";
streamWriter.WriteLine(theString);
Console.WriteLine(theString);
streamWriter.Flush();
theString = streamReader.ReadLine();
Console.WriteLine(theString);
streamReader.Close();
networkStream.Close();
streamWriter.Close();
}
socketForClient.Close();
Console.WriteLine("Exiting...");
}
}

Client Code:

using System;
using System.Net.Sockets;
public class Client
{
static public void Main( string[] Args )
{
TCPClient socketForServer;
try
{
socketForServer =
new TCPClient("localHost", 10);
}
catch
{
Console.WriteLine(
"Failed to connect to server at {0}:999", "localhost");
return;
}
NetworkStream networkStream = socketForServer.GetStream();
System.IO.StreamReader streamReader =
new System.IO.StreamReader(networkStream);
System.IO.StreamWriter streamWriter =
new System.IO.StreamWriter(networkStream);
try
{
string outputString;
// read the data from the host and display it
{
outputString = streamReader.ReadLine();
Console.WriteLine(outputString);
streamWriter.WriteLine("Client Message");
Console.WriteLine("Client Message");
streamWriter.Flush();
}
}
catch
{
Console.WriteLine("Exception reading from Server");
}
// tidy up
networkStream.Close();
}
}

 

           

 

/*
The following example demonstrates the 'Invoke(Delegate)' method of 'Control class.
A 'ListBox' and a 'Button' control are added to a form, containing a delegate
which encapsulates a method that adds items to the listbox.This function is executed
on the thread that owns the underlying handle of the form. When user clicks on button
the above delegate is executed using 'Invoke' method.


*/


using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;

   public class MyFormControl : Form
   {
      public delegate void AddListItem();
      public AddListItem myDelegate;
      private Button myButton;
      private Thread myThread;
      private ListBox myListBox;
      public MyFormControl()
      {
         myButton = new Button();
         myListBox = new ListBox();
         myButton.Location = new Point(72, 160);
         myButton.Size = new Size(152, 32);
         myButton.TabIndex = 1;
         myButton.Text = "Add items in list box";
         myButton.Click += new EventHandler(Button_Click);
         myListBox.Location = new Point(48, 32);
         myListBox.Name = "myListBox";
         myListBox.Size = new Size(200, 95);
         myListBox.TabIndex = 2;
         ClientSize = new Size(292, 273);
         Controls.AddRange(new Control[] {myListBox,myButton});
         Text = " 'Control_Invoke' example";
         myDelegate = new AddListItem(AddListItemMethod);
      }
      static void Main()
      {
         MyFormControl myForm = new MyFormControl();
         myForm.ShowDialog();
      }
      public void AddListItemMethod()
      {
         String myItem;
         for(int i=1;i<6;i++)
         {
            myItem = "MyListItem" + i.ToString();
            myListBox.Items.Add(myItem);
            myListBox.Update();
            Thread.Sleep(300);
         }
      }
      private void Button_Click(object sender, EventArgs e)
      {
         myThread = new Thread(new ThreadStart(ThreadFunction));
         myThread.Start();
      }
      private void ThreadFunction()
      {
         MyThreadClass myThreadClassObject  = new MyThreadClass(this);
         myThreadClassObject.Run();
      }
   }

// The following code assumes a 'ListBox' and a 'Button' control are added to a form,
// containing a delegate which encapsulates a method that adds items to the listbox.

   public class MyThreadClass
   {
      MyFormControl myFormControl1;
      public MyThreadClass(MyFormControl myForm)
      {
         myFormControl1 = myForm;
      }

      public void Run()
      {
         // Execute the specified delegate on the thread that owns
         // 'myFormControl1' control's underlying window handle.
         myFormControl1.Invoke(myFormControl1.myDelegate);
      }
   }

C# Dictionary 키 나열하기

Window based/C# | 2010/01/05 12:00 | Noonipoony

 

           

 

SerializableDictionary<String, LogData>.KeyCollection keyColl = m_dicLogData.Keys;


   foreach (String key in keyColl)
            {
    // 날짜 별로 정렬
    TreeNode currentDateNode = Control_Log_TreeList.Nodes[TreeRootKey].Nodes[m_dicLogData[key].Date];
    if (currentDateNode == null)
    {
     currentDateNode = Control_Log_TreeList.Nodes[TreeRootKey].Nodes.Add(m_dicLogData[key].Date, m_dicLogData[key].Date);
    }
    currentDateNode.Nodes.Add(key, m_dicLogData[key].Title);

            }

이전 1 2 3 4 5 ... 33 다음