本文整理汇总了C#中SocketClient.Send方法的典型用法代码示例。如果您正苦于以下问题:C# SocketClient.Send方法的具体用法?C# SocketClient.Send怎么用?C# SocketClient.Send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SocketClient
的用法示例。
在下文中一共展示了SocketClient.Send方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Handel
public static void Handel(SocketClient client, ForgotPasswordRequest request)
{
var reply = new LoginResponse();
try
{
var user = AccountRepository.GetAccount(null, request.Email);
if (user != null)
{
if (user.Locked)
reply.ResponseType = LoginResponseType.AccountLocked;
else if (user.Verified)
{
user.Locked = true;
user.Verified = false;
user.Verificationcode = Guid.NewGuid().ToString();
reply.AccountId = user.Accountid;
reply.ResponseType = LoginResponseType.ResetSent;
EmailSender.SendRestEmail(user);
BaseRepository.Update(user);
}
else
reply.ResponseType = LoginResponseType.AccountNotVerified;
}
else
reply.ResponseType = LoginResponseType.ResetInvalid;
}
catch (Exception e)
{
reply.ResponseType = LoginResponseType.DatabaseError;
Logger.Error(e.Message);
}
client.Send(reply);
}
示例2: Button_Click
private void Button_Click(object sender, RoutedEventArgs e)
{
SocketClient client = new SocketClient();
string resposta;
client.Connect("10.20.2.124", 6654);
client.Send("nomejogador/" + txtblock1.Text + "/" + txtblock2.Text);
resposta = client.Receive();
/*if (resposta.StartsWith("<ERRO>"))
{
MessageBox.Show(resposta);
}*/
if (resposta == "naocadastrado")
{
MessageBox.Show("Cliente não cadastrado ou senha inválida!");
}
else if (resposta == "naook")
{
MessageBox.Show("Cliente já está logado no sistema!");
}
else
{
NavigationService.Navigate(new Uri("/Menu.xaml", UriKind.RelativeOrAbsolute));
}
}
示例3: SendPacket
//public void SendPacket
public void SendPacket(Packet packet)
{
_communicationClientSettings = new SocketClientSettings
{
KeepAlive = false,
KeepAliveTimeout = 10000,
Reconnect = true,
ReconnectionCount = 10,
ReconnectionTimeout = 10000,
RemoteHost = "127.0.0.1",
RemotePort = 11100,
DataFormat = SocketDataFormat.PACKET
};
_communicationClient = new SocketClient(_communicationClientSettings);
_communicationClient.OnSocketClientEvent += OnCommunicationClientEvent;
_communicationClient.Start();
_communicationClient.Send(packet);
}
示例4: OnConnect
/// <summary>
/// Callback used to accept a connection on the server socket
/// </summary>
/// <param name="asyncResult">The result of the asynchronous operation</param>
/// <remarks>
/// <para>
/// On connection adds to the list of connections
/// if there are two many open connections you will be disconnected
/// </para>
/// </remarks>
private void OnConnect(IAsyncResult asyncResult)
{
try
{
// Block until a client connects
Socket socket = m_serverSocket.EndAccept(asyncResult);
LogLog.Debug(declaringType, "Accepting connection from ["+socket.RemoteEndPoint.ToString()+"]");
SocketClient client = new SocketClient(socket);
int currentActiveConnectionsCount = m_clients.Count;
if (currentActiveConnectionsCount < MAX_CONNECTIONS)
{
try
{
client.Send("TelnetAppender v1.0 (" + (currentActiveConnectionsCount + 1) + " active connections)\r\n\r\n");
AddClient(client);
}
catch
{
client.Dispose();
}
}
else
{
client.Send("Sorry - Too many connections.\r\n");
client.Dispose();
}
}
catch
{
}
finally
{
if (m_serverSocket != null)
{
m_serverSocket.BeginAccept(new AsyncCallback(OnConnect), null);
}
}
}
示例5: DoRequest
/// <summary>
///
/// </summary>
/// <param name="host">远端主机地址</param>
/// <param name="port"></param>
/// <param name="route">远端执行方法名</param>
/// <param name="param">参数</param>
protected void DoRequest(string server, string param)
{
string[] serverArray = server.Split(':');
using (SocketClient client = new SocketClient(serverArray[0], Convert.ToInt32(serverArray[1]), 4096))
{
client.ErrorHandle += DoError;
client.ReceiveHandle += DoReceive;
if (client.Connect())
{
//param = GetRemoteParam(GameID, ServerID, param);
param = param + "&sign=" + GetSign(param);
param = HttpUtility.UrlEncode(param, Encoding.UTF8);
byte[] data = Encoding.UTF8.GetBytes(param);
data = BufferUtils.MergeBytes(BufferUtils.GetSocketBytes(data.Length), data);
client.Send(data);
client.ReceiveResult();
}
}
}
示例6: Handel
public static void Handel(SocketClient client, LoginRequest request, bool bypass)
{
var info = request.AccountInformation;
var reply = new LoginResponse();
var record = BlacklistIpsRepository.GetRecordByMac(client.MAddress) ??
new BlackListedIps {Attempts = 0, MacAddress = client.MAddress};
var address = (IPEndPoint)client.Handler.RemoteEndPoint;
record.Ip = address.Address.ToString();
record.Attempts++;
try
{
if (record.Attempts > 3 && !bypass)
{
if (record.Attempts == 5)
record.BlacklistLiftTime = DateTime.Now.AddMinutes(15);
else if (record.Attempts == 8)
record.BlacklistLiftTime = DateTime.Now.AddMinutes(30);
else if (record.Attempts >= 11)
record.BlacklistLiftTime = DateTime.Now.AddMinutes(record.Attempts*10);
else
{
Handel(client, request, true);
return;
}
BaseRepository.Update(record);
reply.ResponseType = LoginResponseType.TooManyTries;
reply.AccountId = (int) record.BlacklistLiftTime.Subtract(DateTime.Now).TotalMinutes;
}
else
{
BaseRepository.SaveOrUpdate(record);
var account = AccountRepository.GetAccount(info[0], null);
if (account != null)
{
if (account.Locked && !account.Verified)
{
var resetinfo = info[1].Split(':');
if (account.Verificationcode.Equals(resetinfo[0]))
{
account.Locked = false;
account.Verified = true;
account.Password = GetStringSha1Hash(resetinfo[1]);
reply.ResponseType = LoginResponseType.ResetVerified;
BaseRepository.Update(account);
}
else
reply.ResponseType = LoginResponseType.ResetLocked;
}
else if (!account.Locked)
{
if (account.Verified)
{
if (account.Password.Equals(GetStringSha1Hash(info[1])))
{
if (Program.OnlineAccounts.ContainsKey(account.Accountid))
{
reply.ResponseType = LoginResponseType.AccountInUse;
reply.AccountId = account.Accountid;
client.Send(reply);
return;
}
BaseRepository.Remove(record);
reply.AccountId = account.Accountid;
reply.ResponseType = LoginResponseType.Correct;
account.Lastloginip = client.Handler.RemoteEndPoint.ToString();
account.Lastlogintime = DateTime.Today;
BaseRepository.Update(account);
client.Account = account;
client.Send(reply);
HandleSuccessfulLogin(client);
return;
}
reply.ResponseType = LoginResponseType.InvalidPassword;
}
else
{
if (account.Verificationcode.Equals(info[1]))
{
account.Verified = true;
reply.ResponseType = LoginResponseType.AccountVerified;
BaseRepository.Update(account);
}
else
{
reply.AccountId = account.Accountid;
reply.ResponseType = LoginResponseType.AccountNotVerified;
}
}
}
else
reply.ResponseType = LoginResponseType.AccountLocked;
}
else
reply.ResponseType = LoginResponseType.InvalidPassword;
}
}
catch (Exception e)
{
reply.ResponseType = LoginResponseType.DatabaseError;
//.........这里部分代码省略.........
示例7: HandleSuccessfulLogin
private static void HandleSuccessfulLogin(SocketClient client)
{
Program.OnlineAccounts.TryAdd(client.Account.Accountid, client);
var relations = PlayerRelationsRepository.GetAllRelations(client.Account.Accountid);
foreach (var relation in relations)
{
AssociationType relationType;
Enum.TryParse(relation.RelationType.ToString(), out relationType);
switch (relationType)
{
case AssociationType.Friend:
{
var account = AccountRepository.GetAccount(relation.RelationId);
if (account.Accountid == client.Account.Accountid)
account = AccountRepository.GetAccount(relation.AccountId);
if (Program.OnlineAccounts.ContainsKey(account.Accountid))
{
var targetAssossiation = new PlayerAssociation(client.Account.Username.Length)
{
AccountId = client.Account.Accountid,
AssociationExtra = 1,
AssociationType = relation.RelationType,
Username = client.Account.Username
};
Program.OnlineAccounts[account.Accountid].Send(targetAssossiation);
}
var assossiation = new PlayerAssociation(account.Username.Length)
{
AccountId = account.Accountid,
AssociationExtra = (short) (Program.OnlineAccounts.ContainsKey(account.Accountid) ? 1 : 0),
AssociationType = relation.RelationType,
Username = account.Username
};
client.Send(assossiation);
break;
}
case AssociationType.FriendRequest:
{
if (relation.AccountId != client.Account.Accountid)
{
var account = AccountRepository.GetAccount(relation.AccountId);
//requesting account
var assossiation = new PlayerAssociation(account.Username.Length)
{
AccountId = client.Account.Accountid,//receiving account
AssociationType = (short) AssociationType.FriendRequest,
Username = account.Username,//requesting account
AssociationExtra = (short) account.Accountid//requesting account
};
client.Send(assossiation);
}
else
{
var account = AccountRepository.GetAccount(relation.RelationId);
var assossiation = new PlayerAssociation(account.Username.Length)
{
AccountId = client.Account.Accountid,
AssociationType = (short) AssociationType.FriendRequest,
Username = account.Username,
AssociationExtra = (short) account.Accountid
};
client.Send(assossiation);
}
break;
}
}
}
var data = new PlayerData(client.Account.Username.Length)
{
AccountId = client.Account.Accountid,
Username = client.Account.Username
};
client.Send(data);
}
示例8: Handle
public static void Handle( SocketClient client,RegisterRequest request)
{
var registerInfo = request.RegisterInformation;
var user = new Accounts
{
Username = registerInfo[0],
Password = GetStringSha1Hash(registerInfo[1]),
Email = registerInfo[2],
Registerip = client.Handler.RemoteEndPoint.ToString(),
Lastloginip = client.Handler.RemoteEndPoint.ToString(),
Registertime = DateTime.Now,
Lastlogintime = DateTime.Now,
Locked = false,
Verified = false,
Verificationcode = Guid.NewGuid().ToString()
};
var reply = new LoginResponse();
try
{
if (AccountRepository.GetAccount(user.Username, null) == null)
{
if (AccountRepository.GetAccount(null, user.Email) == null)
{
BaseRepository.Add(user);
reply.ResponseType = LoginResponseType.AccountCreated;
reply.AccountId = user.Accountid;
EmailSender.SendWelcomeEmail(user);
}
else
reply.ResponseType = LoginResponseType.EmailInUse;
}
else
reply.ResponseType = LoginResponseType.UsernameInUse;
}
catch (Exception e)
{
reply.ResponseType = LoginResponseType.DatabaseError;
Logger.Error(e.Message);
}
client.Send(reply);
}
示例9: Handle
public static void Handle(SocketClient client, PlayerAssociation playerAssociation)
{
AssociationType aType;
Enum.TryParse(playerAssociation.AssociationType.ToString(), out aType);
switch (aType)
{
case Enums.AssociationType.FriendRequest:
{
var account = AccountRepository.GetAccount(playerAssociation.Username, string.Empty);
//Person targeted for friend.
if (account != null)
{
var relation = new PlayerAssociation(account.Username.Length)
{
AccountId = account.Accountid,
AssociationType = (short) Enums.AssociationType.FriendRequest,
Username = account.Username,
AssociationExtra = (short) client.Account.Accountid
};
client.Send(relation);
if (Program.OnlineAccounts.ContainsKey(account.Accountid))
{
var relation2 = new PlayerAssociation(client.Account.Username.Length)
{
AccountId = account.Accountid,
Username = client.Account.Username,
AssociationType = relation.AssociationType,
AssociationExtra = (short) client.Account.Accountid
};
var player = Program.OnlineAccounts[account.Accountid];
player.Send(relation2);
}
var relationDb = new PlayerRelations()
{
AccountId = relation.AccountId,
RelationId = relation.AssociationExtra,
RelationType = relation.AssociationType
};
BaseRepository.Add(relationDb);
}
break;
}
case Enums.AssociationType.FriendAccept:
{
var relation = PlayerRelationsRepository.GetAllRelations(playerAssociation.AssociationExtra);
foreach (var re in relation)
{
if (re.RelationType == (int) Enums.AssociationType.FriendRequest)
{
if (re.AccountId == playerAssociation.AssociationExtra &&
re.RelationId == playerAssociation.AccountId || re.AccountId == playerAssociation.AccountId &&
re.RelationId == playerAssociation.AssociationExtra)
{
re.RelationType = (short) Enums.AssociationType.Friend;
}
BaseRepository.Update(re);
Accounts account;//Accepted Player
account = AccountRepository.GetAccount(re.AccountId == client.Account.Accountid ? re.RelationId : re.AccountId);
//Accepting player's Packet
var relationPakcet = new PlayerAssociation(account.Username.Length)
{
AccountId = account.Accountid,
AssociationType = (short)Enums.AssociationType.Friend,
Username = account.Username,
AssociationExtra = (short) (Program.OnlineAccounts.ContainsKey(account.Accountid) ? 1 : 0)
};
client.Send(relationPakcet);
if (Program.OnlineAccounts.ContainsKey(account.Accountid))
{
var clientTarget = Program.OnlineAccounts[account.Accountid];
var relationPakcetTarget = new PlayerAssociation(client.Account.Username.Length)
{
AssociationExtra = 1,
AccountId = client.Account.Accountid,
Username = client.Account.Username,
AssociationType = (short) Enums.AssociationType.Friend
};
clientTarget.Send(relationPakcetTarget);
}
}
}
break;
}
case Enums.AssociationType.FriendDeny:
{
break;
}
}
}