public void ReceiveCallback(IAsyncResult ar)
{
socketInfo = ar.AsyncState as SocketInfo;
if (this.OnReceiveMsg != null) OnReceiveMsg();
}
public void ConnectedCallback(IAsyncResult ar)
{
Socket socket = ar.AsyncState as Socket;
if (socket.Connected)
{
if (this.OnConnected != null) OnConnected();
}
else
{
if (this.OnFaildConnect != null) OnFaildConnect();
}
}
public void SendMsg(string msg)
{
byte[] buffer = Encoding.ASCII.GetBytes(msg);
_socket.Send(buffer);
}
public class SocketInfo
{
public Socket socket = null;
public byte[] buffer = null;
public SocketInfo()
{
buffer = new byte[1024 * 4];
}
}
}
public class SocketClientManager
具体源码(.net4.5,vs2013)下载:
------------------------------------------分割线------------------------------------------
具体下载目录在 /2015年资料/1月/29日/C#的Socket简单实现消息发送/
------------------------------------------分割线------------------------------------------