本文整理汇总了C#中System.Net.Sockets.Socket类的典型用法代码示例。如果您正苦于以下问题:C# Socket类的具体用法?C# Socket怎么用?C# Socket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Socket类属于System.Net.Sockets命名空间,在下文中一共展示了Socket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:Valdiralita,项目名称:RawCraft,代码行数:7,代码来源:AesStream.cs
示例2: ClientConnection
public ClientConnection(Socket socket)
: base(socket)
{
DisconnectedEvent += ClientConnection_DisconnectedEvent;
m_LittleEndian = true;
Logger.Trace("Client {0}: Connected", this);
}
开发者ID:ExpTeam,项目名称:trunk,代码行数:7,代码来源:ClientConnection.cs
示例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;
}
}
开发者ID:zwagoth,项目名称:whip-dotnet-client,代码行数:25,代码来源:AuthChallenge.cs
示例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);
}
}
开发者ID:Season02,项目名称:MK2.0,代码行数:29,代码来源:socket.cs
示例5: ProcessQueue
public ProcessQueue(int _cardNo, Player _user, Socket _userSocket, Player _target)
{
cardNo = _cardNo;
user = _user;
target = _target;
userSocket = _userSocket;
}
开发者ID:Ilumia,项目名称:TheVampire_server,代码行数:7,代码来源:RoomInfoProcessing.cs
示例6: AbstractSession
public AbstractSession(Socket sck)
{
this.Actived = false;
this.Socket = sck;
this.Handle = sck.Handle.ToInt32();
this.RemoteEndpoint = sck.RemoteEndPoint.ToString();
}
开发者ID:robert0609,项目名称:BlueFox,代码行数:7,代码来源:AbstractSession.cs
示例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;
}
开发者ID:zacglenn,项目名称:GroupActivityFeed,代码行数:27,代码来源:GroupActivityFeedConnector.cs
示例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);
}
}
开发者ID:omariom,项目名称:corefx,代码行数:7,代码来源:SocketPal.Unix.cs
示例9: Dispose
public void Dispose()
{
Socket.Disconnect(false);
Socket.Shutdown(SocketShutdown.Both);
Socket.Close();
Socket = null;
}
开发者ID:GennadyKharlam,项目名称:TCP-C-Sharp-server,代码行数:7,代码来源:Client.cs
示例10: Client
public Client(Socket s)
{
clientSocket = s;
//启动一个线程处理客户端的数据接收
t = new Thread(ReceiveMessage);
t.Start();
}
开发者ID:vin120,项目名称:c-shap-code,代码行数:7,代码来源:Client.cs
示例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;
}
开发者ID:wulinfeng2008,项目名称:SuperSocket,代码行数:7,代码来源:AsyncSocketSession.cs
示例13: WorkerProxy
public WorkerProxy(NagCoordinator coordinator, Socket socket)
{
Worker = new TCPConnection(socket, false, ProcesLine, null);
NagCoordinator = coordinator;
State = ConnectionState.Negotiating;
Negotiate();
}
开发者ID:tgiphil,项目名称:GoTraxx,代码行数:7,代码来源:WorkerProxy.cs
示例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;
}
}
开发者ID:babywzazy,项目名称:Server,代码行数:36,代码来源:TcpAsyncSocketListener.cs
示例15: OnlineUser
public OnlineUser(Socket socket, String username, String token, String publicKey)
{
WorkSocket = socket;
Username = username;
this.token = token;
PublicKey = publicKey;
}
开发者ID:fridsamt,项目名称:WordAddIn_Server,代码行数:7,代码来源:OnlineUser.cs
示例16: DestorySocket
public static int DestorySocket(Socket socket)
{
int r = -1;
try
{
//if (_socket.Connected)
//{
// _socket.Disconnect(false);
//}
if (socket != null)
{
socket.Shutdown(SocketShutdown.Both);
socket.DisconnectAsync(null);
socket.Close();
socket.Dispose();
socket = null;
}
r = 0;
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
r = -1;
}
return r;
}
开发者ID:Microshaoft,项目名称:Microshaoft.Common.Utilities.Net.4x,代码行数:28,代码来源:SocketHelper.cs
示例17: CheckConnection
/// <summary>
/// Checks the connection.
/// </summary>
/// <param name="sock">The sock.</param>
/// <param name="maxIpConnectionCount">The maximum ip connection count.</param>
/// <param name="antiDDosStatus">if set to <c>true</c> [anti d dos status].</param>
/// <returns><c>true</c> if XXXX, <c>false</c> otherwise.</returns>
internal static bool CheckConnection(Socket sock, int maxIpConnectionCount, bool antiDDosStatus)
{
if (!antiDDosStatus)
return true;
string iP = sock.RemoteEndPoint.ToString().Split(':')[0];
if (iP == _mLastIpBlocked)
return false;
if (GetConnectionAmount(iP) > maxIpConnectionCount)
{
Writer.WriteLine(iP + " was banned by Anti-DDoS system.", "Yupi.Security", ConsoleColor.Blue);
_mLastIpBlocked = iP;
return false;
}
int freeConnectionId = GetFreeConnectionId();
if (freeConnectionId < 0)
return false;
_mConnectionStorage[freeConnectionId] = iP;
return true;
}
开发者ID:sgf,项目名称:Yupi,代码行数:34,代码来源:SocketConnectionCheck.cs
示例18: InfoDataDeal
//处理服务器收到的信息数据,返回gameuser信息
public static GameUser InfoDataDeal(MySQLCtrl mySQLCtrl, Socket socket, string infoStr)
{
string[] strTemp = DataCtrl.SegmentData(infoStr);
GameUser gameuser = new GameUser();
switch (strTemp[0])
{
//收到注册数据
case "0":
string[] infos = DataCtrl.SegmentData(infoStr.Substring(2));
if (mySQLCtrl.IsExistInDb(infos[0]))
{ gameuser.Status = "0|0|0|注册邮箱已存在|"; return gameuser; }
if (mySQLCtrl.IsNickNameExistInDb(infos[1]))
{ gameuser.Status = "0|0|0|注册昵称已存在|"; return gameuser; }
RegisterDeal(mySQLCtrl, socket, infos, out gameuser);
return gameuser;
//收到登陆数据
case "1":
string[] loadInfo = DataCtrl.SegmentData(infoStr.Substring(2));
if (!mySQLCtrl.IsExistInDb(loadInfo[0]))
{ gameuser.Status = "0|1|0|登录邮箱未注册|"; return gameuser; }
SignDeal(mySQLCtrl, socket, loadInfo, out gameuser);
return gameuser;
default: return null;
}
}
开发者ID:div8ivb,项目名称:Citadels,代码行数:26,代码来源:InfoDataCtrl.cs
示例19: AcceptConnection
/// <summary>
/// Accepts incoming npc service connection.
/// </summary>
/// <param name="s">Accepted <see cref="Socket"/> object.</param>
internal static void AcceptConnection( Socket s )
{
if ( s == null || !s.Connected )
return;
if ( !Active )
{
NetworkHelper.RemoteServiceInfo info = NetworkHelper.GetServiceInfo(s);
if ( info.ServiceType == ServiceType.NpcService )
{
m_NpcServerConnection = new InnerNetworkClient(info.ServiceId, info.ServiceType, s);
NpcServiceRequestsHandlers nsrh = new NpcServiceRequestsHandlers(ref m_NpcServerConnection);
//m_NpcServerConnection.OnDisconnected += new OnDisconnectedEventHandler(NpcServerConnection_OnDisconnected);
m_NpcServerConnection.HandleDelegate = nsrh.Handle;
m_NpcServerConnection.Send(new InitializeResponse(Settings.Default.ServiceUniqueID, ( byte )ServiceType.GameService, InitializeResponse.Accepted).ToPacket());
Active = true;
Logger.WriteLine(Source.InnerNetwork, "Connection accepted for {0} (0x{1})", info.ServiceType, info.ServiceId.ToString("x2"));
}
}
}
开发者ID:Hefester,项目名称:l2c-devsadmin,代码行数:29,代码来源:ConnectionsManager.cs
示例20: RoomDataDeal
/// <summary>
/// 创建房间数据处理
/// </summary>
/// <param name="roomSeatSockets">要操作的socket字典</param>
/// <param name="roomNum">要操作的房间号</param>
/// <param name="socket">对应的客户端socket</param>
/// <param name="roomStr">对应的接收到的房间数据</param>
/// <returns>成功返回true,否则返回false</returns>
public static string RoomDataDeal(GameDataCenter gameDataCenter, Socket socket, string roomStr)
{
string[] strTemp = DataCtrl.SegmentData(roomStr);
switch (strTemp[0])
{
//创建房间的信息,房间号++,建立socket的list,加入当前socket,将当前list加入dic,如果对应的房间号的list包含此socket,加入对应的playerdata,返回true,否则,返回false。
case "0":
int roomNum = 1;
while(gameDataCenter.RoomDataDic.Keys.Contains(roomNum))
{
roomNum++;
}
gameDataCenter.RoomNum= roomNum;
List<Socket> l = new List<Socket>();
l.Add(socket);
gameDataCenter.RoomSeatSockets.Add(gameDataCenter.RoomNum, l);
if (gameDataCenter.RoomSeatSockets[gameDataCenter.RoomNum].Contains(socket))
{
GameRoomData gameRoomData = new GameRoomData();
PlayerData playerData = new PlayerData(1, gameDataCenter.MailNickDic[strTemp[1]],strTemp[1],socket);
playerData.IsKing = true;
gameRoomData.PlayerDataDic.Add(1,playerData);
gameDataCenter.RoomDataDic.Add(gameDataCenter.RoomNum, gameRoomData);
//更新所有的在大厅中的人的信息,同时更新特定房间的人的信息
RoomDataPushAll(gameDataCenter);
RoomDataPush(gameDataCenter, roomNum);
return "1|0|1|" + gameDataCenter.RoomNum.ToString() + "|" + gameDataCenter.RoomSeatSockets[gameDataCenter.RoomNum].Count.ToString() + "|";
}
else
{
gameDataCenter.RoomNum--;
return "1|0|0|创建失败|";
}
//加入房间的信息,先取得房间号i,判断房间号i存在否,存在则将此socket加入list,如果此list含此socket,返回true。
case "1":
int i;
int.TryParse(strTemp[1], out i);
if (!gameDataCenter.RoomSeatSockets.Keys.Contains(i)) { return "1|1|0|加入失败|"; }
gameDataCenter.RoomSeatSockets[i].Add(socket);
if (gameDataCenter.RoomSeatSockets[i].Contains(socket))
{
PlayerData playerData = new PlayerData(gameDataCenter.RoomSeatSockets[i].Count, gameDataCenter.MailNickDic[strTemp[1]], strTemp[1],socket);
gameDataCenter.RoomDataDic[i].PlayerDataDic.Add(gameDataCenter.RoomDataDic[i].PlayerDataDic.Count+1, playerData);
//更新所有的在大厅中的人的信息,同时更新特定房间的人的信息
RoomDataPushAll(gameDataCenter);
RoomDataPush(gameDataCenter, i);
return "1|1|1|" + i + "|" + gameDataCenter.RoomSeatSockets[i].Count.ToString() + "|"; }
else
{ return "1|1|0|加入失败|"; }
//更新房间信息
case "2":
string strRoomDataUpdate = RoomDataUpdate(gameDataCenter, socket, strTemp);
return strRoomDataUpdate;
default: return "未知错误";
}
}
开发者ID:div8ivb,项目名称:Citadels,代码行数:68,代码来源:InfoDataCtrl.cs
注:本文中的System.Net.Sockets.Socket类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论