Skip to content

Commit 2f7269a

Browse files
committed
Signed-off-by: Dodo(NickName) <rabbit.white@daum.net>
0 parents  commit 2f7269a

27 files changed

+822
-0
lines changed
42.5 KB
Binary file not shown.

.vs/JasperMultiThreadClient/v16/Server/sqlite3/db.lock

Whitespace-only changes.
588 KB
Binary file not shown.

JasperMultiThreadClient.sln

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio Version 16
4+
VisualStudioVersion = 16.0.29411.108
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "JasperMultiThreadClient", "JasperMultiThreadClient\JasperMultiThreadClient.csproj", "{253BDA1D-E845-400D-BA44-8984A51BB8B8}"
7+
EndProject
8+
Global
9+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
10+
Debug|Any CPU = Debug|Any CPU
11+
Release|Any CPU = Release|Any CPU
12+
EndGlobalSection
13+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14+
{253BDA1D-E845-400D-BA44-8984A51BB8B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{253BDA1D-E845-400D-BA44-8984A51BB8B8}.Debug|Any CPU.Build.0 = Debug|Any CPU
16+
{253BDA1D-E845-400D-BA44-8984A51BB8B8}.Release|Any CPU.ActiveCfg = Release|Any CPU
17+
{253BDA1D-E845-400D-BA44-8984A51BB8B8}.Release|Any CPU.Build.0 = Release|Any CPU
18+
EndGlobalSection
19+
GlobalSection(SolutionProperties) = preSolution
20+
HideSolutionNode = FALSE
21+
EndGlobalSection
22+
GlobalSection(ExtensibilityGlobals) = postSolution
23+
SolutionGuid = {BE3D5FE3-9D9F-4616-9FF4-DDABAD276BC2}
24+
EndGlobalSection
25+
EndGlobal

JasperMultiThreadClient/App.config

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<configuration>
3+
<startup>
4+
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
5+
</startup>
6+
</configuration>

JasperMultiThreadClient/Form1.Designer.cs

Lines changed: 128 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

JasperMultiThreadClient/Form1.cs

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.ComponentModel;
4+
using System.Data;
5+
using System.Drawing;
6+
using System.Linq;
7+
using System.Net;
8+
using System.Net.Sockets;
9+
using System.Text;
10+
using System.Threading;
11+
using System.Threading.Tasks;
12+
using System.Windows.Forms;
13+
14+
namespace JasperMultiThreadClient
15+
{
16+
public partial class Form1 : Form
17+
{
18+
Thread thTimerThread;
19+
TcpClient clientSocket = new TcpClient();
20+
NetworkStream serverStream;
21+
22+
string address;
23+
int port;
24+
25+
public Form1()
26+
{
27+
InitializeComponent();
28+
}
29+
30+
private void Form1_Load(object sender, EventArgs e)
31+
{
32+
address = "127.0.0.1";
33+
port = 8888;
34+
lblServerStatus.Text = DateTime.Now + " 환영합니다.(Welcome)";
35+
36+
thTimerThread = new Thread(serverTimerStart);
37+
thTimerThread.Start();
38+
}
39+
40+
public void serverTimerStart()
41+
{
42+
43+
while (true)
44+
{
45+
refreshTimer.Interval = 3000;
46+
refreshTimer.Enabled = true;
47+
refreshTimer.Start();
48+
}
49+
50+
}
51+
52+
private void refreshTimer_Tick(object sender, EventArgs e)
53+
{
54+
try
55+
{
56+
clientSocket.Connect(address, port);
57+
lblServerStatus.Text = "서버 작동중...(Server On...)";
58+
recvMessage();
59+
60+
}
61+
catch (Exception ex)
62+
{
63+
lblServerStatus.Text = "서버 멈췄음(Server Stopped)";
64+
txtMessages.Text = txtMessages.Text + Environment.NewLine +
65+
ex.ToString();
66+
}
67+
}
68+
69+
public void recvMessage()
70+
{
71+
NetworkStream serverStream = clientSocket.GetStream();
72+
byte[] inStream = new byte[65536];
73+
serverStream.Read(inStream, 0, (int)clientSocket.ReceiveBufferSize);
74+
75+
string returnData = System.Text.Encoding.UTF8.GetString(inStream);
76+
txtMessages.Text = txtMessages.Text + Environment.NewLine + ">>" + returnData;
77+
78+
}
79+
80+
private void btnSend_Click(object sender, EventArgs e)
81+
{
82+
sendMessage();
83+
}
84+
85+
public void sendMessage()
86+
{
87+
string localIP = GetLocalIP();
88+
string usrNickname = txtNickname.Text;
89+
string usrMessage = txtSend.Text;
90+
91+
// 닉네임
92+
if (usrNickname == "")
93+
{
94+
usrNickname = "익명(Anonymous)";
95+
}
96+
97+
// 메시지(message)
98+
if ( usrMessage == "")
99+
{
100+
usrMessage = localIP + ";" + usrNickname + ";\0";
101+
}
102+
else
103+
{
104+
usrMessage = localIP + ";" + usrNickname + ";" + usrMessage;
105+
}
106+
107+
// 연결 여부(Connection)
108+
if (clientSocket.Connected == true)
109+
{
110+
serverStream = clientSocket.GetStream();
111+
byte[] outStream = System.Text.Encoding.UTF8.GetBytes(usrMessage);
112+
serverStream.Write(outStream, 0, outStream.Length);
113+
serverStream.Flush();
114+
}
115+
else
116+
{
117+
try
118+
{
119+
clientSocket.Connect(address, port);
120+
lblServerStatus.Text = "서버 작동중...(Server On...)";
121+
serverStream = clientSocket.GetStream();
122+
byte[] outStream = System.Text.Encoding.UTF8.GetBytes(usrMessage);
123+
serverStream.Write(outStream, 0, outStream.Length);
124+
serverStream.Flush();
125+
recvMessage();
126+
}
127+
catch (Exception ex)
128+
{
129+
MessageBox.Show("대상 컴퓨터에서 연결을 거부했으므로 연결하지 못했습니다.\n" +
130+
"(Failed to connect because the destination computer refused to connect.)",
131+
"메시지(Message)", MessageBoxButtons.OK, MessageBoxIcon.Information);
132+
lblServerStatus.Text = "오류(Error)";
133+
txtMessages.Text = txtMessages + Environment.NewLine +
134+
ex.ToString();
135+
}
136+
}
137+
}
138+
139+
public string GetLocalIP()
140+
{
141+
string localIP = "Not available, please check your network seetings!";
142+
IPHostEntry host = Dns.GetHostEntry(Dns.GetHostName());
143+
foreach (IPAddress ip in host.AddressList)
144+
{
145+
if (ip.AddressFamily == AddressFamily.InterNetwork)
146+
{
147+
localIP = ip.ToString();
148+
break;
149+
}
150+
}
151+
return localIP;
152+
}
153+
154+
private void Form1_FormClosed(object sender, FormClosedEventArgs e)
155+
{
156+
thTimerThread.Abort();
157+
}
158+
}
159+
}

0 commit comments

Comments
 (0)