Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö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#¶ÔͼƬµÄ¼¸ÖÖ¼òµ¥´¦Àí

ÓÖÓÐÒ»¶Îʱ¼äûÓиüÐÂÁË£¬È±ÉÙѧϰµÄÈÈÇéÁË¡£½ñÌìÌù¼¸¸öͼƬ´¦ÀíµÄС¼¼ÇÉ£¬Ï£Íû¶Ô´ó¼ÒÓÐÓãº
(1)ÈçºÎ»ñÈ¡.gifͼƬÖеĸ÷¸öÖ¡£¿
(2)ÈçºÎ»ñȡͼƬµÄËõÂÔͼ£¿
(3)ÈçºÎ“½ØÈ¡”ͼƬµÄÖ¸¶¨ÇøÓò£¿
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Drawing.Imaging;
public class ImageHelp ......

C#±¾ÖÊÂÛ

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