本文整理汇总了C#中System.Net.Sockets.Socket类的典型用法代码示例。如果您正苦于以下问题:C# Socket类的具体用法?C# Socket怎么用?C# Socket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Socket类属于System.Net.Sockets命名空间,在下文中一共展示了Socket类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AesStream
public AesStream(Socket socket, EnhancedStream stream, byte[] key)
: base(socket)
{
BaseStream = stream;
_enc = new CryptoStream(stream, GenerateAES(key).CreateEncryptor(), CryptoStreamMode.Write);
_dec = new CryptoStream(stream, GenerateAES(key).CreateDecryptor(), CryptoStreamMode.Read);
}
示例2: ClientConnection
public ClientConnection(Socket socket)
: base(socket)
{
DisconnectedEvent += ClientConnection_DisconnectedEvent;
m_LittleEndian = true;
Logger.Trace("Client {0}: Connected", this);
}
示例3: AuthChallenge
public AuthChallenge(Socket conn)
{
int soFar = 0;
byte[] buffer = new byte[MESSAGE_SIZE];
while (soFar < MESSAGE_SIZE)
{
//read the header and challenge phrase
int rcvd = conn.Receive(buffer, (int)MESSAGE_SIZE - soFar, SocketFlags.None);
if (rcvd == 0) throw new AuthException("Disconnect during authentication");
if (soFar == 0 && buffer[0] != PACKET_IDENTIFIER) throw new AuthException("Invalid challenge packet header");
//skip the first byte
if (soFar == 0)
{
if (rcvd > 1) _challenge.Append(buffer, 1, rcvd - 1);
}
else
{
_challenge.Append(buffer, 0, rcvd);
}
soFar += rcvd;
}
}
示例4: reConnect
public void reConnect()
{
serviceSocket.Close();
serviceSocket = null;
sendBuffer = new byte[1024];//Send buffer //c# automatic assigesd to 0
try
{
serviceSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
System.Threading.Thread tt = new System.Threading.Thread(delegate()
{
try
{
serviceSocket.Connect(ip, port);
}
catch (Exception ee)
{
//MessageBox.Show(ee.Message + "\r\n From:" + this);
}
});
tt.Start();
}
catch (Exception e)
{
//MessageBox.Show(e.Message + "\r\n From:" + this);
}
}
示例5: ProcessQueue
public ProcessQueue(int _cardNo, Player _user, Socket _userSocket, Player _target)
{
cardNo = _cardNo;
user = _user;
target = _target;
userSocket = _userSocket;
}
示例6: AbstractSession
public AbstractSession(Socket sck)
{
this.Actived = false;
this.Socket = sck;
this.Handle = sck.Handle.ToInt32();
this.RemoteEndpoint = sck.RemoteEndPoint.ToString();
}
示例7: initializeConnection
public bool initializeConnection()
{
try
{
m_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);
m_socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
m_socket.SendTimeout = 5000;
m_socket.ReceiveTimeout = 5000;
m_frm.Print("Connecting to " + ECCServerIP + " at port " + ECCServerPort + " ...");
m_socket.Connect(ECCServerIP, Convert.ToInt32(ECCServerPort));
}
catch (Exception ex)
{
m_frm.Print("Error!Failed to connect to ECC server!" + ex.Message);
return false;
}
if (!Authenticate())
return false;
return true;
}
示例8: CheckDualModeReceiveSupport
public static void CheckDualModeReceiveSupport(Socket socket)
{
if (!SupportsDualModeIPv4PacketInfo && socket.AddressFamily == AddressFamily.InterNetworkV6 && socket.DualMode)
{
throw new PlatformNotSupportedException(SR.net_sockets_dualmode_receivefrom_notsupported);
}
}
示例9: Dispose
public void Dispose()
{
Socket.Disconnect(false);
Socket.Shutdown(SocketShutdown.Both);
Socket.Close();
Socket = null;
}
示例10: Client
public Client(Socket s)
{
clientSocket = s;
//启动一个线程处理客户端的数据接收
t = new Thread(ReceiveMessage);
t.Start();
}
示例11: OSUserToken
// The read socket that creates this object sends a copy of its "parent" accept socket in as a reference
// We also take in a max buffer size for the data to be read off of the read socket
public OSUserToken(Socket readSocket, Int32 bufferSize, IEFMagLinkRepository repository)
{
_repository = repository;
ownersocket = readSocket;
stringbuilder = new StringBuilder(bufferSize);
}
开发者ID:Cocotus,项目名称:High-Performance-.NET-Socket-Server-Using-Async-Winsock,代码行数:9,代码来源:OSUserToken.cs
示例12: AsyncSocketSession
public AsyncSocketSession(Socket client, SocketAsyncEventArgsProxy socketAsyncProxy, bool isReset)
: base(client)
{
SocketAsyncProxy = socketAsyncProxy;
m_OrigOffset = socketAsyncProxy.SocketEventArgs.Offset;
m_IsReset = isReset;
}
示例13: WorkerProxy
public WorkerProxy(NagCoordinator coordinator, Socket socket)
{
Worker = new TCPConnection(socket, false, ProcesLine, null);
NagCoordinator = coordinator;
State = ConnectionState.Negotiating;
Negotiate();
}
示例14: Start
/// <summary>
/// 启动监听
/// </summary>
/// <param name="config">服务器配置</param>
/// <returns></returns>
public override bool Start(IServerConfig config)
{
m_ListenSocket = new System.Net.Sockets.Socket(this.Info.EndPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
try
{
//关联终结地
m_ListenSocket.Bind(this.Info.EndPoint);
//设置监听最大连接数
m_ListenSocket.Listen(m_ListenBackLog);
m_ListenSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, true);
m_ListenSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);
//初始化套接字操作
SocketAsyncEventArgs acceptEventArg = new SocketAsyncEventArgs();
m_AcceptSAE = acceptEventArg;
//定义一个连接完成事件
acceptEventArg.Completed += new EventHandler<SocketAsyncEventArgs>(acceptEventArg_Completed);
if (!m_ListenSocket.AcceptAsync(acceptEventArg))
{
ProcessAccept(acceptEventArg);
}
return true;
}
catch (Exception e)
{
OnError(e);
return false;
}
}
示例15: OnlineUser
public OnlineUser(Socket socket, String username, String token, String publicKey)
{
WorkSocket = socket;
Username = username;
this.token = token;
PublicKey = publicKey;
}