다음 예제는 클라이언트가 객체를 서버로 전송후 DB에 넣고, 다시 서버가 DB에서 객체를 읽어서 클라이언트로 보내는 예제입니다 DB에 객체가 삽입될 memo 컬럼은 longtext 타입입니다 CREATE TABLE memo ( DB는 mysql을 사용했습니다 DB마다 약간씩 차이가 있더군요 참고하십시오 ------------- 서버 ------------- class Program Socket m_listenSocket; MyClass myClass = new MyClass(); Console.WriteLine("서버 시작"); m_listenSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); m_listenEP = new IPEndPoint(IPAddress.Any, 555); m_listenSocket.Bind(m_listenEP); m_clientSocket = m_listenSocket.Accept(); while (true) // 수신된 MemoryStream을 Base64String으로 변환 // 객체 string을 DB에 삽입 cmd.Dispose(); // DB에서 불러오기 // 객체 string을 byte로 변환 // 객체 byte를 클라이언트로 send cmd.Dispose(); m_listenSocket.Close(); } ------------- 클라이언트 ------------- class Program Console.WriteLine("클라이언트 시작"); MemoryStream ms = new MemoryStream(); MyClass myClass = new MyClass(); // 객체를 ms로 변환 int LENGTH = (int)ms.Length; while (true) // 서버 로부터 객체 수신 while (true) // ms 스트림을 객체로 변환 Console.WriteLine(myClass2.ID); ms.Close(); //소멸. |
'2008/C#'에 해당되는 글 16건
- 2008.07.25 객체 TCP로 전송후 DB에 저장하기 (2)
- 2008.07.25 객체 TCP로 전송후 DB에 저장하기 (1)
- 2008.06.23 MDI Form 에 대한 연구
- 2008.06.03 Member Insert - 회원등록 프로그램 Project #1
- 2008.05.19 Calculation - 계산기 프로그램 Project #1
- 2008.05.15 함수형 멤버를 연구해 보자 #1
객체 TCP로 전송후 DB에 저장하기 (1) 클라이언트에서 객체를 서버로 전송해서 DB에 저장하는 방법입니다 (클라이언트) 객체 -> 직렬화 -> 소켓 --- 소켓 -> 객체 -> DB저장 (서버) 이런 식으로 돌아갑니다. 데이터 타입을 변환하는 과정들이 있어서 사전지식이 몇 가지 필요합니다 1. MemoryStream 2. Object(객체) 3. Base64String 4. Byte[] 이 4가지 타입을 주로 다룹니다 데이타 타입에 대해서는 각자 찾아 보시기 바랍니다 밑에 소스는 변환을 쉽게 하고자 만들어봤습니다 틀린 부분 있으면 알려주세요 using System;
ms.Position = 0; return obj; // MemoryStream을 byte[]로 변환 return buffer; // MemoryStream을 Base64String로 변환 return base64EncodedString; // Object를 MemoryStream으로 변환 binFmtr.Serialize(ms, obj); ms.Position = 0; return ms; // Object를 byte[]로 변환 binFmtr.Serialize(ms, obj); ms.Position = 0; return buffer; // Object를 Base64String로 변환 ms.Position = 0; string base64EncodedString = Convert.ToBase64String(buffer); return base64EncodedString;
// byte[]를 Object로 변환 ms.Write(buffer, 0, buffer.Length); // byte[]를 Base64String 으로 변환 // Base64String을 MemoryStream로 변환 ms.Write(buffer, 0, buffer.Length); return ms; // Base64String을 Object로 변환 byte[] buffer = Convert.FromBase64String(base64EncodedString); return obj; |
데브피아 이은호님
MID Form 이란? Multiple Document Interface의 약자로 간략하게 설명을 하자면
한폼안에 여러게의 폼을 또 생성하는 거다.
즉, 한글 프로그램을 보면 여러 문서를 뛰우지 않는가? 그렇게
생각 하자!!
C# 으로 MDI Form을 만들어 봅시다.
힌트;;;
-------------------------------------------------------------------
Child Form에서
public MainForm mainForm;
public void Initialize()
{
this.Location = new Point(0, 0);
this.StartPosition = FormStartPosition.Manual;
this.FormBorderStyle = FormBorderStyle.None;
this.WindowState = FormWindowState.Normal;
this.Dock = DockStyle.Fill;
}
Main Form 에서...
버튼 클릭시
private void toolBarCreatePlan_Click(object sender, EventArgs e)
{
ICS.IssuePlan.frmCreatePlan form = new ICS.IssuePlan.frmCreatePlan();
if (ToolBarShow(form) == false)
{
form.Text = "발급계획수립";
//////form.issuePlanList = _IssuePlanList;
ShowMdiForm(form, form.Text, form.Text);
}
}
public void ShowMdiForm(Common.ChildForm form, string state, string title)
{
form.Location = new Point(0, 0); ;
form.StartPosition = FormStartPosition.Manual;
form.FormBorderStyle = FormBorderStyle.None;
form.WindowState = FormWindowState.Normal;
ICS.Common.ChildForm forms = new ICS.Common.ChildForm();
form.mainForm = this;
form.MdiParent = this;
form.remote = this._remoting;
form.commFunc = this.commonFunc;
form.Text = title;
form.Closed += new EventHandler(MainForm.ProgressMain.formCloseEvent);
form.Show();
SetTitleBar(title);
}
#region ToolBarShow : ToolBar 클릭시 Form 생성 유무 확인
public bool ToolBarShow(object form)
{
for (int i = 0; i < this.MdiChildren.Length; i++)
{
if (this.MdiChildren[i].GetType().ToString().Equals(form.GetType().ToString()) == true)
{
this.MdiChildren[i].BringToFront();
return true;
}
}
return false;
}
#endregion
public void SetTitleBar(string title)
{
//local Host Ip/Name 가져오기
string hostIpName = GetHostIpName();
if (hostIpName != "")
{
hostIpName = " [ " + hostIpName + " ]";
}
if (title != null && title != "")
this.Text = "발급 제어 시스템(ICS)" + " - " + title + hostIpName;
else
this.Text = "발급 제어 시스템(ICS)" + " " + hostIpName;
}
#endregion
-----------------------------------------------------------------------
회원등록 프로젝트
: 이번 프로젝트의 목적은 프로그램을 통해서 DB에 데이터를 조작하는 방법을 습득
하기 위한 프로젝트이다.
1. 환경 OS : Windows Vista
DB : Oracle 11g
Program : C#
------------------------------
Windows Vista 에 Oracle 11g 설치 하기.
11g 설치시 주의 사항
1. 사용자 계정명은 영어로 되어야 한다. 설치 도중에 에러 발생
2. 설치 폴더의 경로에 공백이 있거나 한글이 있어서는 안된다. 마찬가지로 에러발생.
3. 적당한 HDD의 공간
4. Microsoft Loopback Adapter 설치 및 10.10.10.10 /255.255.255.0 설정
(하드웨어 추가에서 네트워크 어뎁터를 선택후 추가 설치를 하면 된다.)
위의 4가지를 우선 기본적으로 지키면 별 탈 없이 설치가 가능하다.
Oracle 11g 설치 후 행해야 할 계정 생성및 권한 설정
sqlplus "/as sysdba"
접속이 되면
SQL> show user 명령을 통하여 현재 사용자를 확인 한다.
User은 "SYS" 입니다. <= 라는 결과가 나올것이다.
그다음으로는 내가 막 가지고놀 계정을 만들어야 된다.
SQL> create user sewoo identified by ******(비밀번호);
그럼 해당 계정의 생성과 비밀번호를 설정한 것이다.
마지막으로 해당 생성계정으로 몬가를 할 수 있게 권한등을 줘야 한다.
SQL> grant connect, resource, dba to sewoo;
위와 같이 연결, 테이블 생성등 DBA 권한등.. 을 sewoo에게 주자 ㅎㅎ
이것으로 기본적인 DB 설정을 완료 하였다. 추후 실력을 늘리다 보면 추가적으로
Oracle란에 잘 정리하여 작성하겠다.
//2008년 5월 19일 박세우 작성 sewooim골뱅이.네이버점캄
동아리 과제 1 이걸 Pass 해야 다음단계로 ^^*
1. 동적으로 버튼을 임의로 만들기
2. 좀더 struct 나 class 를 만들어서 활용해보자.
-------------------------------------------
설명 : 해당 내용은 닷넷 2008로 제작하였습니다. 그림 -> 내용 설명 식으로 작성하겠습니다.
-------------------------------------------
1) 버튼 위치 및 버튼 기능 설정 class
using System;
using System.Collections.Generic;
using System.Text;
namespace Calculation
{
/*
* 버튼을 동적으로 할당하게 합니다.
* Class Name : ViewButton
* Method Name : BtnSetting
*/
class ViewButton
{
static System.Windows.Forms.Button[] _btn = new System.Windows.Forms.Button[10];
public System.Windows.Forms.Button [] btn
{
get {return _btn; }
set {_btn = value; }
}
public ViewButton()
{
for (int i = 0; i < _btn.Length; i++)
{
_btn[i] = new System.Windows.Forms.Button(); // Hip Memory에 할당 합니다.
}
}
public void BtnView()
{
for (int i = 0; i < _btn.Length; i++)
{
_btn[i].Text = i.ToString();
_btn[i].Size = new System.Drawing.Size(40,20);
_btn[i].Name = i.ToString();
_btn[i].Tag = i.ToString();
BtnPosition();
}
}
private void BtnPosition()
{
int w;
int p = w = 0;
for (int i = _btn.Length -1; i >= 0; i--)
{
if (i % 3 == 0)
{
if (i == 9)
{
p = 10;
w = 200;
_btn[i].Location = new System.Drawing.Point(w, p);
}
p += 20;
w = 200;
_btn[i].Location = new System.Drawing.Point(w, p);
}
else
{
w -= 50;
_btn[i].Location = new System.Drawing.Point(w,p);
}
}
}
}
}
---------------
Form1.cs
public partial class Form1 : Form
{
ViewButton vb;
string ok;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
vb = new ViewButton();
vb.BtnView();
for (int i = 0; vb.btn.Length > i; i++)
{
this.panel1.Controls.Add(vb.btn[i]);
vb.btn[i].Click += new EventHandler(Button_Click);
}
}
void Button_Click(object sender, EventArgs e)
{
Control ctl = (Control)sender;
ok += ctl.Tag.ToString();
this.labNum.Text = ok;
}
private void button1_Click(object sender, EventArgs e)
{
op = new Operation();
op["+"] = labNum.Text;
labNum.Text = null;
}
}
}
---------------
Operation.cs
namespace Calculating
{
class Operation
{
private int values;
private int Result = 0;
public string this[string what]
{
get
{
switch (what)
{
case "=": return Result.ToString();
default: return "";
}
}
set
{
switch (what)
{
case "+":
values = value;
break;
default: break;
}
}
}
}
}
보호되어 있는 글입니다.
내용을 보시려면 비밀번호를 입력하세요.