C# TCP 服务端(PC)与客户端(PPC) 简单代码
服务器端代码
控件:btnStart_Click,btnSend_Click,label4,textBox1
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Collections;
using System.Threading;
using System.Net.Sockets;
using System.Net;
namespace MobileServer
{
public partial class FrmEasy : Form
{
//变量
private ThreadStart start;
private Thread listenThread,client_th;
static private bool m_bListening = false;
//static private System.Net.IPAddress MyIP = System.Net.IPAddress.Parse("192.168.1.3");
//获得当前服务端的IP 地址
static private System.Net.IPAddress MyIP = Dns.Resolve(Dns.GetHostName()).AddressList[0];
static private TcpListener listener = new TcpListener(MyIP, 5567);
private String msg;
ArrayList clientArray = new ArrayList();
public FrmEasy()
{
InitializeComponent();
Control.CheckForIllegalCrossThreadCalls = false;
start = new ThreadStart(startListen);
listenThread = new Thread(start);
}
private void btnStart_Click(objec
相关文档:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
namespace ConsoleApplication4
{
class Program
{
static void Main(string[] args)
{
//sqlserver身份验证
//s ......
关于使用到了两个C#关键字this和base。
1,C# "this " keyword
其作用引用类的当前实例,其实看了下面这个例子就好理解了。
主要三个作用:当前实例、参数传递和索引器
1.1 当前实例
class Team
{
///成员变量
private string name;
///构造函数
......
public string WriteXML(string[] values, int flag)
{
//如果flag==0则为第一次运行需要初始化XML文件
if (flag == 0)
{
//生在随机文件名
string dateName = System.DateTime.Now.ToString("yyyyMMddHHmmss");
......
方法一:遍历正在有相同名字运行的例程
using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace DHPSS.COM
{
/// <summary>
/// c#程序只运行一次,C#例程只运行一次
/// http://blog.csdn.net/nnsw ......
Observer.cs
using System;
using System.Text;
using System.Collections.Generic;
namespace Observer
{
public interface ISubject
{
void RegisterObserver(IOvserver o);
& ......