'Photobook' 카테고리의 다른 글
Windows7 Wallpaper 대한민국 (0) | 2010.11.30 |
---|---|
Windows7 Wallpaper Landscapes (0) | 2010.11.30 |
Windows7 Wallpaper 캐릭터 (0) | 2010.11.30 |
Windows7 Wallpaper 조형물 (0) | 2010.11.30 |
Windows7 Wallpaper 수채화 (0) | 2010.11.30 |
Windows7 Wallpaper 대한민국 (0) | 2010.11.30 |
---|---|
Windows7 Wallpaper Landscapes (0) | 2010.11.30 |
Windows7 Wallpaper 캐릭터 (0) | 2010.11.30 |
Windows7 Wallpaper 조형물 (0) | 2010.11.30 |
Windows7 Wallpaper 수채화 (0) | 2010.11.30 |
// Server Socket
// NameSpace 선언
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ServerSideSocket
{
class ServerClass
{
public static Socket Server , Client;
public static byte[] getByte = new byte[1024];
public static byte[] setByte = new byte[1024];
public const int sPort = 5000;
[STAThread]
static void Main(string[] args)
{
string stringbyte = null;
IPAddress serverIP = IPAddress.Parse("127.0.0.1");
IPEndPoint serverEndPoint = new IPEndPoint(serverIP,sPort);
try
{
Server= new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
Server.Bind(serverEndPoint);
Server.Listen(10);
Console.WriteLine("-----------------------------------------------------");
Console.WriteLine(" 클라이언트의 연결을 기다립니다........ ");
Console.WriteLine("-----------------------------------------------------");
Client = Server.Accept();
if(Client.Connected)
{
while(true)
{
Client.Receive(getByte,0,getByte.Length,SocketFlags.None);
stringbyte = Encoding.UTF7.GetString(getByte);
if (stringbyte != String.Empty)
{
int getValueLength = 0;
getValueLength = byteArrayDefrag(getByte);
stringbyte = Encoding.UTF7.GetString(getByte,0,getValueLength+1);
Console.WriteLine("수신데이터:{0} | 길이:{1}",stringbyte,getValueLength+1);
setByte = Encoding.UTF7.GetBytes(stringbyte);
Client.Send(setByte,0,setByte.Length,SocketFlags.None);
}
getByte = new byte[1024];
setByte = new byte[1024];
}
}
}
catch(System.Net.Sockets.SocketException socketEx)
{
Console.WriteLine("[Error]:{0}", socketEx.Message);
}
catch(System.Exception commonEx)
{
Console.WriteLine("[Error]:{0}", commonEx.Message);
}
finally
{
Server.Close();
Client.Close();
}
}
public static int byteArrayDefrag(byte[] sData)
{
int endLength = 0;
for(int i = 0; i < sData.Length; i++)
{
if((byte)sData[i] != (byte)0)
{
endLength = i;
}
}
return endLength;
}
}
}
// Client Socket
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;
namespace ClientSideSocket
{
class ClientClass
{
public static Socket socket;
public static byte[] getbyte = new byte[1024];
public static byte[] setbyte = new byte[1024];
public const int sPort = 5000;
[STAThread]
static void Main(string[] args)
{
string sendstring = null;
string getstring = null;
IPAddress serverIP = IPAddress.Parse("127.0.0.1");
IPEndPoint serverEndPoint = new IPEndPoint(serverIP,sPort);
socket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
Console.WriteLine("-----------------------------------------------------");
Console.WriteLine(" 서버로 접속을 시작합니다. [엔터를 입력하세요] ");
Console.WriteLine("-----------------------------------------------------");
Console.ReadLine();
socket.Connect(serverEndPoint);
if (socket.Connected)
{
Console.WriteLine(">> 정상적으로 연결 되었습니다.(전송한 데이터를 입력해주세요)");
}
while(true)
{
Console.Write(">>");
sendstring = Console.ReadLine();
if(sendstring != String.Empty)
{
int getValueLength = 0;
setbyte = Encoding.UTF7.GetBytes(sendstring);
socket.Send(setbyte,0,setbyte.Length,SocketFlags.None);
Console.WriteLine("송신 데이터 : {0} | 길이{1}", sendstring, setbyte.Length);
socket.Receive(getbyte,0,getbyte.Length,SocketFlags.None);
getValueLength = byteArrayDefrag(getbyte);
getstring = Encoding.UTF7.GetString(getbyte,0,getValueLength+1);
Console.WriteLine(">>수신된 데이터 :{0} | 길이{1}" , getstring , getValueLength+1);
}
getbyte = new byte[1024];
}
}
public static int byteArrayDefrag(byte[] sData)
{
int endLength = 0;
for(int i = 0; i < sData.Length; i++)
{
if((byte)sData[i] != (byte)0)
{
endLength = i;
}
}
return endLength;
}
}
}
MFC 소켓을 이용한 파일전송 코드(기본적인 부분만) (0) | 2010.12.16 |
---|---|
MFC 소켓프로그램 기초 예제와 네트워크 기본개념 (0) | 2010.12.16 |
MFC 쓰레드(thread) 예제 (0) | 2010.11.22 |
현재 시간 얻어오기 (0) | 2010.11.16 |
Editbox 컨트롤 사용방법 (0) | 2010.11.16 |
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Thread_Test
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
}
private void button_start_Click(object sender, EventArgs e)
{
Thread T1 = new Thread(M1);
Thread T2 = new Thread(M2);
CheckForIllegalCrossThreadCalls = false; //크로스쓰레드 체크 옵션을 꺼주거나
T1.Start();
T2.Start();
}
private void M1()
{
for (int i = 0; i < 10000; i++)
listBox_output.Items.Add("Thread1");
//this.Invoke(new MethodInvoker(delegate { this.listBox_output.Items.Add("Thread1"); })); 이 방법처럼 invoke를 이용한다
}
private void M2()
{
for (int i = 0; i < 10000; i++)
listBox_output.Items.Add("Thread2");
//this.Invoke(new MethodInvoker(delegate { this.listBox_output.Items.Add("Thread2"); }));
}
}
}
크로스쓰레트 체크 옵션을 false로 변경할 경우 컨트롤들의 동작이 Visual Studio 2003의 동작방식과 동일해진다고 하는데 세세한 내용은 모르겠음
메인폼(메인쓰레드)에서 생성한 컨트롤들을 다른 신규 쓰레드들에서 접근하려 하면 크로스쓰레드 발생
새로운 규칙에 맞게 가능하면 컨트롤들은 get(), set()등을 이용하여 별도로 접근(음... 뭔가 더욱 객체지향적으로 가겠다는건가...)하는것이 좋겠다
파일을 선택해서 원하는 위치에 복사하는 프로그램
fileCopyDlg.cpp
void CFilecopyDlg::OnFrom()
{
// TODO: Add your control notification handler code here
m_ctrlListBox.ResetContent();
char szFilter[] = "All Files(*.*)|*.*||";
CFileDialog dlg(TRUE, NULL, NULL, OFN_ALLOWMULTISELECT, szFilter);
if(IDOK == dlg.DoModal())
for(POSITION pos = dlg.GetStartPosition(); pos!=NULL;)
m_ctrlListBox.AddString(dlg.GetNextPathName(pos));
}
void CFilecopyDlg::OnTo()
{
// TODO: Add your control notification handler code here
ITEMIDLIST *pidlBrowse;
char pszPathname[MAX_PATH];
BROWSEINFO BrInfo;
BrInfo.hwndOwner = GetSafeHwnd();
BrInfo.pidlRoot = NULL;
memset(&BrInfo, 0, sizeof(BrInfo));
BrInfo.pszDisplayName = pszPathname;
BrInfo.lpszTitle = "복사할 폴더를 선택하시오";
BrInfo.ulFlags = BIF_RETURNONLYFSDIRS;
//대화상자 띄우기
pidlBrowse = ::SHBrowseForFolder(&BrInfo);
if(pidlBrowse != NULL)
{
//Path를 얻어옴
SHGetPathFromIDList(pidlBrowse, pszPathname);
m_strDest = pszPathname;
UpdateData(FALSE);
}
}
void CFilecopyDlg::OnStartCopy()
{
// TODO: Add your control notification handler code here
UpdateData();
SHFILEOPSTRUCT *pF0 = new SHFILEOPSTRUCT;
pF0->hwnd = NULL;
pF0->wFunc = FO_COPY;
pF0->fFlags = FOF_NOCONFIRMMKDIR;
pF0->fAnyOperationsAborted = TRUE;
pF0->lpszProgressTitle = _T("파일 복사중");
CMemFile file;
CArchive ar(&file, CArchive::store);
CString str;
int nCount = m_ctrlListBox.GetCount();
char null = 0;
for(int i=0;i<nCount;i++)
{
m_ctrlListBox.GetText(i, str);
ar.WriteString(str);
ar.Write(&null, 1);
}
ar.Write(&null, 1);
ar.Close();
pF0->pFrom = (char *)file.Detach();
//복사될 디렉토리명(Destination)
pF0->pTo = new char[m_strDest.GetLength()+1];
strcpy((LPSTR)pF0->pTo, (LPSTR)(LPCTSTR)m_strDest);
((LPSTR)pF0->pTo)[m_strDest.GetLength()]=0;
AfxBeginThread(ThreadFunc, pF0);
}
UINT ThreadFunc(LPVOID pParam)
{
SHFILEOPSTRUCT *pF0 = (SHFILEOPSTRUCT *)pParam;
::SHFileOperation(pF0);
delete [] (char *)pF0->pFrom;
delete [] (char *)pF0->pTo;
delete pF0;
return 0;
}
fileCopyDlg.h
class CFileCopyDlg : public Cdialog
외부에
UINT ThreadFunc(LPVOID pParam);
를 선언해줌
MFC 소켓프로그램 기초 예제와 네트워크 기본개념 (0) | 2010.12.16 |
---|---|
C# 소켓 예제 (Server, Client) (0) | 2010.11.29 |
현재 시간 얻어오기 (0) | 2010.11.16 |
Editbox 컨트롤 사용방법 (0) | 2010.11.16 |
클래스들 간의 상호참조 (0) | 2010.11.16 |
봉하마을 평일 밤 풍경 (0) | 2017.02.09 |
---|---|
봉하마을 방문기 3편 (0) | 2010.11.17 |
봉하마을 방문기 2편 (0) | 2010.11.17 |
봉하마을 방문기 1편 (0) | 2010.11.17 |
이곳은 말씀 안드려도 다들 아시지요?...
깊은 한숨이 나옵니다
4편 에서 계속 할께요...
봉하마을 평일 밤 풍경 (0) | 2017.02.09 |
---|---|
봉하마을 방문기 4편 (3) | 2010.11.17 |
봉하마을 방문기 2편 (0) | 2010.11.17 |
봉하마을 방문기 1편 (0) | 2010.11.17 |
봉하마을 평일 밤 풍경 (0) | 2017.02.09 |
---|---|
봉하마을 방문기 4편 (3) | 2010.11.17 |
봉하마을 방문기 3편 (0) | 2010.11.17 |
봉하마을 방문기 1편 (0) | 2010.11.17 |
봉하마을 평일 밤 풍경 (0) | 2017.02.09 |
---|---|
봉하마을 방문기 4편 (3) | 2010.11.17 |
봉하마을 방문기 3편 (0) | 2010.11.17 |
봉하마을 방문기 2편 (0) | 2010.11.17 |
///////////////////////////////////////////////////////////////////////////////
//STL( list )
//이중 링크드 리스트처럼 임의의 위치에 삽입과 삭제가 빠름
//임의의 위치에 엑세스 할 수 없으며, 순차적으로 엑세스 하여 검색할 수 있다.
//순차 컨테이너
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <list>
using namespace std;
void main()
{
list<int> List;
list<int>::iterator it;
List.push_back(10);
List.push_back(9);
List.push_back(8);
List.push_back(7);
List.push_back(6);
cout << "List크기" << List.size() << endl;
for( it = List.begin(); it != List.end(); it++ )
{
cout << *it << endl;
}
List.push_front(11);
List.push_front(12);
cout << "List크기" << List.size() << endl;
for( it = List.begin(); it != List.end(); it++ )
{
cout << *it << endl;
}
}
///////////////////////////////////////////////////////////////////////////////
//STL( list )
//list를 이용하여 링크드 리스트 구현하기.
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <list>
#include <algorithm>
using namespace std;
enum { INPUT = 1, DELETE, OUTPUT, EXIT };
void main()
{
int select;
int val;
list<int> list1;
list<int>::iterator it;
while(1)
{
cout << "선택하세요( [1]:입력, [2]:삭제, [3]:출력, [4]:나가기 ) : ";
cin >> select;
switch( select )
{
case INPUT:
cout << "입력할 값을 입력하세요 : ";
cin >> val;
list1.push_back(val);
break;
case DELETE:
cout << "삭제할 값을 입력하세요 : ";
cin >> val;
it = find( list1.begin(), list1.end(), val ); //입력한 값을 찾아서 이터레이터를 리턴.
list1.erase(it);
break;
case OUTPUT:
for( it = list1.begin(); it != list1.end(); it++ )
{
cout << *it << endl;
}
break;
case EXIT:
cout << "Bye~" << endl;
return;
}
}
}
///////////////////////////////////////////////////////////////////////////////
//STL( list )
//구조체 변수를 사용하기.
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <list>
using namespace std;
typedef struct tag_Number {
char name[10];
int num;
}NUMBER;
NUMBER *pNum = NULL;
list<NUMBER*> list1;
list<NUMBER*>::iterator it;
void Input();
void Output();
void main()
{
Input();
Output();
delete pNum;
}
void Input()
{
int sel;
while(1)
{
cout << "[1] : 입력, [5] : 나가기";
cin >> sel;
if( sel == 5 ) break;
else if( sel == 1 )
{
pNum = new NUMBER;
cout << "이름을 입력하세요 : ";
cin >> pNum->name;
cout << "전화번호를 입력하세요 : ";
cin >> pNum->num;
list1.push_back( pNum ); //리스트가 동적으로 할당하는 pNum을 가지고 있는다.
//구조체를 가지게 하지말고 주소값을 가지게 할것.
}
}
}
void Output()
{
for( it = list1.begin(); it != list1.end(); it++ )
{
cout << (*it)->name << endl;
cout << (*it)->num << endl;
}
}
map - map의 index에 의해 정렬되어 값이 출력 (0) | 2010.11.16 |
---|---|
set - 랜덤하게 값을 집어 넣으면서 중복값을 빼고 소팅 (0) | 2010.11.16 |
stack (0) | 2010.11.16 |
vector - 가변길이의 순차적인 배열에 대한 임의의 접근 가능 (0) | 2010.11.16 |
///////////////////////////////////////////////////////////////////////////////
//STL( map )
//map의 index에 의해서 정렬되어 값이 출력됨.
//index키값을 이용해 신속하게 값을 찾을 수 있다.
//중복된 index를 허용하지 않는다.
//정력컨테이너 : 키값을 이용해서 데이터를 신속하게 찾을 수 있다.
///////////////////////////////////////////////////////////////////////////////
#include <iostream>
#include <map>
using namespace std;
void main()
{
map<int, char*> map1;
map<int, char*>::iterator it;
map1[3] = "yi";
map1[2] = "ki";
map1[1] = "ho";
for( it = map1.begin(); it != map1.end(); it++ )
{
cout << it->first << it->second << endl;
}
map1[1] = "wow";
map1[3] = "hi";
for( it = map1.begin(); it != map1.end(); it++ )
{
cout << it->first << it->second << endl;
}
map1.erase(3); //index키값을 이용해 쉽게 자료를 삭제할 수도 있다.
for( it = map1.begin(); it != map1.end(); it++ )
{
cout << it->first << it->second << endl;
}
}
list (0) | 2010.11.16 |
---|---|
set - 랜덤하게 값을 집어 넣으면서 중복값을 빼고 소팅 (0) | 2010.11.16 |
stack (0) | 2010.11.16 |
vector - 가변길이의 순차적인 배열에 대한 임의의 접근 가능 (0) | 2010.11.16 |