Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

Socket±à³Ì(C#)

//Socket»ù±¾±à³Ì
//·þÎñ¶Ë£º
using System.Net;
using System.Net.Sockets;
using System.Text;
using System.Threading;
Thread mythread ;
Socket socket;
// ÇåÀíËùÓÐÕýÔÚʹÓõÄ×ÊÔ´¡£
protected override void Dispose( bool disposing )
{
try
¡¡ { ¡¡¡¡
¡¡¡¡ socket.Close();//ÊÍ·Å×ÊÔ´
¡¡¡¡ mythread.Abort ( ) ;//ÖÐÖ¹Ïß³Ì
¡¡ }
¡¡ catch{ }
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
public static IPAddress GetServerIP()
{
IPHostEntry ieh=Dns.GetHostByName(Dns.GetHostName());
return ieh.AddressList[0];
}
private void BeginListen()
{
IPAddress ServerIp=GetServerIP();
IPEndPoint iep=new IPEndPoint(ServerIp,8000);
socket=new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
byte[] byteMessage=new byte[100];
this.label1.Text=iep.ToString();
socket.Bind(iep);
// do
while(true)
{
try
{
socket.Listen(5);
Socket newSocket=socket.Accept();
newSocket.Receive(byteMessage);
string sTime = DateTime.Now.ToShortTimeString ( ) ;
string msg=sTime+":"+"Message from:";
msg+=newSocket.RemoteEndPoint.ToString()+Encoding.Default.GetString(byteMessage);
this.listBox1.Items.Add(msg);
}
catch(SocketException ex)
{
this.label1.Text+=ex.ToString();
}
}
// while(byteMessage!=null);
}
//¿ªÊ¼¼àÌý
private void button1_Click(object sender, System.EventArgs e)
{
try
{
mythread = new Thread(new ThreadStart(BeginListen));
mythread.Start();
}
catch(System.Exception er)
{
MessageBox.Show(er.Message,"Íê³É",MessageBoxButtons.OK,MessageBoxIcon.Stop);
}
}
//¿Í»§¶Ë£º
using System.Net;
using System.Net.Sockets;
using System.Text;
private void button1_Click(object sender, System.EventArgs e)
{
BeginSend();
}
private void BeginSend()
{
string ip=this.txtip.Text;
string port=this.txtport.Text;
IPAddress serverIp=IPAddress.Parse(ip);
int serverPort=Convert.ToInt32(port);
IPEndPoint iep


Ïà¹ØÎĵµ£º

ʹÓÃC#ÕýÔò±í´ïʽƥÅäÏà¹Ø×Ö·û´®

C#ÕýÔò±í´ïʽƥÅä×Ö·û´®µÄ·½·¨ÈçÏ£º
1.ʹÓÃC#ÖÐʹÓÃÕýÔò±í´ïʽSystem.Text.RegularExpressionsÃüÃû¿Õ¼ä£»
2.ʹÓÃC#ÖÐʹÓÃÕýÔò±í´ïʽMatches()·½·¨Æ¥Åä×Ö·û´®£¬¸ñʽÈçÏ£º
MatchCollection Matches = Regex.Matches(Str, Pattern, RegexOptions.IgnoreCase | RegexOptions.ExplicitC ......

C#ʵÏÖÎļþ¹ØÁª

ºÍÆäËûÓïÑÔÒ»Ñù£¬C#ʵÏÖÎļþ¹ØÁªÍ¬ÑùÐèÒªÖ±½Ó²Ù×÷×¢²á±í£¬¼´°´¹æÔò·Ö±ðÉèÖÃÎļþÀ©Õ¹Ãû£¬ÎĵµÀàÐÍ˵Ã÷£¬ÓѺÃÃû³Æ£¬Í¼±ê£¬µ÷Ó÷½·¨µÈ¼üÖµ¼´¿É£¬ÍøÉÏËæ±ã²é²é¾Í¿ÉÒÔд³öÒÔϵĴúÂë¡£ using Microsoft.Win32; RegistryKey key = Registry.ClassesRoot.OpenSubKey(".jb");
if (key == null)
{
 ......

C#ͳ¼Æ¿á¹·²¥·ÅÁбíÀï¸èÇú²¥·ÅµÄ×Üʱ¼ä

ÊÖ»úÒôÀÖ²¥·¢Æ÷ÀïÓÐ×ÜÎļþ×Üʱ¼äµÄͳ¼Æ£¬ÔÚ¿á¹·²¥·ÅÆ÷ÀïÕÒÁËÒ»ÏÂûÕÒµ½¡£ÄÇÎÒÏëÖªµÀÕâЩ¸èÇúµÄ×Üʱ¼ä£¬¸ÃÔõô°ì£¿
ÆäʵºÜ¼òµ¥£¬ÉÔÉÔ¶¯¶¯ÊÖ£¬¾ÍÄÜÕÒµ½´ð°¸£¡
Çë²Î¿¼Èçϲ½Ö裺
µÚÒ»²½£¬±£´æ²¥·ÅÁÐ±í£¬°ÑÀïÃæµÄ¸èÇú±£´æµ½Ò»¸öÄãϲ»¶µÄÃû×Ö¡£
µÚ¶þ²½£¬ÔÚ²¥·ÅÁбíÉÏÃæµãÓÒ¼ü£¬µ½´¦²¥·ÅÁÐ±íµ½ÄãÕҵĵ½µÄµØ·½¡£
¾­²âÊÔ£¬×îР......

C#Ô¤´¦ÀíÆ÷Ö¸ÁîÈëÃÅ

Ò»¡¢C#Ô¤´¦ÀíÆ÷Ö¸ÁîÈëÃÅ #define NET11  //NET11,NET20,(±ØÐë·ÅÔÚÎļþµÚÒ»ÐÐ)
using System;
//¡­ ¡­
//¡­ ¡­
//¡­ ¡­

string sBeepType = s.Replace(sKey,"");
#if NET20
int.TryParse(sBeepType,out beepType); //ÔÚ.net 2.0ÖвÅÓеķ½·¨
#endif
#if ......

C#±¾ÖÊÂÛ

»ùÀàµÄÖØд£º
new:£¨½öÕë¶ÔÅÉÉúÀàÓÃÅÉÉúʵÀýµ÷ÓÃʱ²ÅÆð×÷Óã¬Ä¿µÄÊÇÔÚÅÉÉúÀàÖÐÓÃÀ´¸²¸Ç»ùÀàµÄ·½·¨£©
1.ÅÉÉúÀ๹½¨³ÉµÄʵÀý£¬µ±µ÷ÓÃÓÉnew ÐÞÊεķ½·¨Ê±£¬¸²¸Ç»ùÀànew ·½·¨¡£
2.ÅÉÉúÀ๹½¨³ÉµÄʵÀý¸³¸ø»ùÀà±äÁ¿Ê±£¬ÔÙµ÷ÓÃÓÉnew ÐÞÊεķ½·¨Ê±£¬½«Ö´ÐлùÀàÖеķ½·¨¡£
virtual¡¢override
1.ÓÉÅÉÉúÀ๹½¨µÄʵÀý£¬²»¹ÜÊÇÓÃÅÉÉ ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ