随笔分类 -  C# 网络编程

摘要:第一种方法: public static byte[] GetImagePixel(Bitmap img) { byte[] result = new byte[img.Width*img.Height*3]; int n = 0; for (int i = 0; i < img.Height; i++) { for (int j = 0; j < img.Width; j++) { result[... 阅读全文
posted @ 2013-05-21 15:31 louiskoo 阅读(14370) 评论(0) 推荐(0) 编辑
摘要:客户端:byteData = Encoding.UTF8.GetBytes(message);服务端:string receivedString = Encoding.UTF8.GetString(byteData,0,length); 阅读全文
posted @ 2013-02-15 21:09 louiskoo 阅读(2663) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net;using System.Net.Sockets;using System.Threading;namespace MyAsyncClient{ class Program { static void Main(string[] args) { startClient(); } public static Ma... 阅读全文
posted @ 2013-02-12 21:22 louiskoo 阅读(946) 评论(0) 推荐(0) 编辑
摘要:实现多客户端向服务器发送数据using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Net;using System.Net.Sockets;namespace MyAsyncServer{ class Program { private static byte[] byteData = new byte[1024]; static void Main(stri... 阅读全文
posted @ 2013-02-12 00:28 louiskoo 阅读(855) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading;using System.Net;using System.Net.Sockets;namespace MyAsyncServer{ class Program { private static byte[] byteData = new byte[1024]; static void Main(string[] args) ... 阅读全文
posted @ 2013-02-12 00:04 louiskoo 阅读(3392) 评论(0) 推荐(0) 编辑
摘要:serverSocket.BeginAccept( new AsyncCallback(AcceptedCallback), serverSocket); client.BeginConnect( ipEnd, new AsyncCallback(ConnectedCallback), client);会连接不上,加上public static ManualResetEvent connEvent = new ManualRe... 阅读全文
posted @ 2013-02-11 23:40 louiskoo 阅读(1660) 评论(0) 推荐(0) 编辑
摘要:http://www.cnblogs.com/peterzb/archive/2009/05/29/1491605.html 阅读全文
posted @ 2013-02-10 22:17 louiskoo 阅读(149) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Net;using System.Net.Sockets;using System.Text;public class SynchronousSocketClient { public static void StartClient() { // Data buffer for incoming data. byte[] bytes = new byte[1024]; // Connect to a remote device. try { // Establ... 阅读全文
posted @ 2013-02-10 21:09 louiskoo 阅读(206) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Net;using System.Net.Sockets;using System.Text;public class SynchronousSocketListener { // Incoming data from the client. public static string data = null; public static void StartListening() { // Data buffer for incoming data. byte[] bytes = new ... 阅读全文
posted @ 2013-02-10 21:08 louiskoo 阅读(201) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Net;using System.Net.Sockets;using System.Text;using System.Threading;// State object for reading client data asynchronouslypublic class StateObject{ // Client socket. public Socket workSocket = null; // Size of receive buffer. public const int BufferSize = 102... 阅读全文
posted @ 2013-02-10 21:02 louiskoo 阅读(302) 评论(0) 推荐(0) 编辑
摘要:using System;using System.Net;using System.Net.Sockets;using System.Threading;using System.Text;// State object for receiving data from remote device.public class StateObject{ // Client socket. public Socket workSocket = null; // Size of receive buffer. public const int BufferSize = 256;... 阅读全文
posted @ 2013-02-10 21:01 louiskoo 阅读(254) 评论(0) 推荐(0) 编辑
摘要:AsyncServer: Bind - Listen - BeginAccept - EndAccept - BeginReceive - EndReceive - BeginSend - EndSend - Shutdown - CloseAcceptCallbackReadCallbackSendCallbackAsyncClient: BeginConnect - EndConnect -BeginSend - EndSend - BeginReceive - EndReceive- Shutdown - Close ConnectCallbackSendCallback Receive 阅读全文
posted @ 2013-02-10 20:57 louiskoo 阅读(225) 评论(0) 推荐(0) 编辑
摘要:执行顺序不一样 private static int newTask(int mms) { //C } private delegate int NewTaskDelegate(int mms); static void Main(string[] args) { //A NewTaskDelegate newTst = newTask; IAsyncResult asyncResult = newT... 阅读全文
posted @ 2013-02-10 01:19 louiskoo 阅读(184) 评论(0) 推荐(0) 编辑
摘要:BeginInvoke需要加委托才能行,否则会出错,给你段代码参考以下:BeginInvoke 所调用的委托根本就是在 UI 线程中执行的BeginInvoke实现了事件的异步执行,如实例: private static int newTask(int mms) { Console.WriteLine("任务开始"); Thread.Sleep(mms); Random random = new Random(); int n = random.Next(10000); ... 阅读全文
posted @ 2013-02-09 23:00 louiskoo 阅读(328) 评论(0) 推荐(0) 编辑
摘要:User:using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Net.Sockets;using System.IO;namespace AsyncTcpServer{ class User { public TcpClient client { get; private set; } public BinaryReader br { get; private set; } public BinaryWr... 阅读全文
posted @ 2013-02-09 17:34 louiskoo 阅读(2439) 评论(0) 推荐(2) 编辑
摘要:服务器端:namespace SocketTest{ class Program { public static void SendMessage() { Socket socket = serverSocket.Accept(); Console.WriteLine("Connected a client:{0}",socket.RemoteEndPoint); socket.Send(Encoding.ASCII.GetBytes("welcome to server"));... 阅读全文
posted @ 2013-02-01 13:21 louiskoo 阅读(19599) 评论(1) 推荐(1) 编辑
摘要:由于线程安全问题,在多线程编程下更改一个控件的属性时,往往需要用托管来更改属性的值.下面是一个通用的托管,用反射来对属性进行赋值.public delegate void SetValueCallBack(Control control, string property, object value);public static void SetValue(Control control, string property, object value)...{ if (control.InvokeRequired) control.Invoke(new SetValueCa... 阅读全文
posted @ 2013-01-28 18:52 louiskoo 阅读(288) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示