📄 winmsg.cs
字号:
/*
<Aicaca Community Messenger Client>
Copyright (c) Aicaca.com, All rights reserved.
Writer : Byung-ku, Cho (Aicaca)
E-mail : aicaca@hanmail.net
Personal Homepage URL : http://www.aicaca.com
Last Updated Date : Feb. 27th, 2002
Programming Language : C#
Editor & Compiler : VisualStudio.NET
*/
using System;
using System.IO;
using System.Threading;
using System.ComponentModel;
using System.Windows.Forms;
using System.Net;
using System.Net.Sockets;
namespace TalkClient
{
public class WinMsg
{
private WinCom WC = new WinCom();
private WinClient xWinClient;
private WinDialog xWinDialog;
private Socket DialogSocket = null;
private string localID;
private string clientID;
private string sendStr;
public WinMsg(WinClient tWinClient, WinDialog tWinDialog, Socket tDialogSocket)
{
xWinClient = tWinClient;
xWinDialog = tWinDialog;
DialogSocket = tDialogSocket;
}
public WinMsg(WinClient tWinClient, WinDialog tWinDialog, string tLocalID, string tClientID, string tSendStr)
{
xWinClient = tWinClient;
xWinDialog = tWinDialog;
localID = tLocalID;
clientID = tClientID;
sendStr = tSendStr;
}
public void CloseThis()
{
if (this.DialogSocket != null)
{
this.DialogSocket.Close();
}
}
private void OnReceive(string str)
{
str = str.Substring(0, str.Length-1);
string sort = WC.GetXML(str, "ms");
switch(sort)
{
case "ILOVEAICACAMSG":
xWinDialog.OnILOVEAICACAMSG(str);
break;
case "ILOVEAICACAERR":
xWinDialog.OnILOVEAICACAERR(str);
break;
}
}
public void ServerProc()
{
string strOne = "";
string str = "";
char[] c = new char[1];
if (DialogSocket != null && DialogSocket.Connected)
{
NetworkStream stream = new NetworkStream(DialogSocket);
TextReader SocketReader = new StreamReader(stream);
try
{
while (SocketReader.Read(c,0,1) != 0)
{
strOne = new String(c);
str += strOne;
if (strOne == "\n")
{
this.OnReceive(str);
str = "";
}
}
}
catch (Exception e)
{
}
if (DialogSocket != null)
{
DialogSocket.Close();
DialogSocket = null;
}
}
}
public void ClientProc()
{
string strOne = "";
string str = "";
char[] c = new char[1];
string clientIP = WC.GetXML(clientID, "ci");
int clientPort = Convert.ToInt32(WC.GetXML(clientID, "cp"));
DialogSocket = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPAddress host_addr = Dns.GetHostByAddress(clientIP).AddressList[0];
IPEndPoint ep = new IPEndPoint(host_addr, clientPort);
try
{
DialogSocket.Connect(ep);
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
xWinClient.SendRootMsg(sendStr);
return;
}
if (DialogSocket != null && DialogSocket.Connected)
{
NetworkStream stream = new NetworkStream(DialogSocket);
TextReader SocketReader = new StreamReader(stream);
xWinDialog.pDialogSocket = DialogSocket;
xWinDialog.SendMsg(sendStr);
try
{
while (SocketReader.Read(c,0,1) != 0)
{
strOne = new String(c);
str += strOne;
if (strOne == "\n")
{
this.OnReceive(str);
str = "";
}
}
}
catch (Exception e)
{
}
if (DialogSocket != null)
{
DialogSocket.Close();
DialogSocket = null;
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -