|
You last visited: Today at 09:32
Advertisement
Sockets bother me
Discussion on Sockets bother me within the CO2 Private Server forum part of the Conquer Online 2 category.
05/17/2017, 16:27
|
#1
|
elite*gold: 0
Join Date: Sep 2014
Posts: 194
Received Thanks: 52
|
Sockets bother me
Hello,
I have came into a problem with my source, i'm using async sockets and after a while their memory usage increases rapidly, i think it's something related to something called "overlapping", i've tried googling it but couldn't find a solution. Any ideas? or tutorials how to write effecient sockets.
|
|
|
05/17/2017, 18:16
|
#2
|
elite*gold: 12
Join Date: Jul 2011
Posts: 8,282
Received Thanks: 4,191
|
Post the socket system here, and maybe we can take a look at it.
|
|
|
05/17/2017, 19:40
|
#3
|
elite*gold: 0
Join Date: Sep 2014
Posts: 194
Received Thanks: 52
|
The socket system is inspired by Redux and Phoenix. I've been using this for a while and i think the problem comes from here.
PHP Code:
using System;
using System.Net;
using System.Text;
using System.Linq;
using System.Net.Sockets;
namespace PureConquer.Network.ServerSocket
{
public delegate void NetworkClientConnection(Wrapper client);
public delegate void NetworkClientReceive(byte[] buffer, int length, Wrapper client);
public class SocketServer
{
public Socket Socket { get; private set; }
public IPEndPoint LocalEndPoint { get; private set; }
public NetworkClientConnection OnConnect;
public NetworkClientReceive OnReceive;
public NetworkClientConnection OnDisconnect;
public BruteForceAttackProtection AttackProtector;
public int ClientBufferSize;
public SocketServer(uint maximum = 50, uint banTime = 60)
{
AttackProtector = new BruteForceAttackProtection(maximum, banTime);
}
public void Prepare(int port, int backlog, IPProtectionLevel protectionLevel)
{
LocalEndPoint = new IPEndPoint(IPAddress.Any, port);
Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
Socket.Bind(LocalEndPoint);
Socket.SetIPProtectionLevel(protectionLevel);
Socket.NoDelay = true;
Socket.Listen(backlog);
}
public void BeginAccept()
{
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.KeepAlive, false);
Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.DontLinger, true);
Socket.BeginAccept(Accept, null);
}
private void Accept(IAsyncResult result)
{
Socket clientSocket;
try
{
clientSocket = Socket.EndAccept(result);
}
catch (SocketException)
{
BeginAccept();
return;
}
if (AttackProtector.Authenticate(clientSocket))
{
clientSocket.ReceiveBufferSize = ClientBufferSize;
var client = new Wrapper(this, clientSocket, ClientBufferSize);
InvokeOnConnect(client);
client.BeginReceive();
}
else
clientSocket.Disconnect(false);
BeginAccept();
}
public void InvokeOnConnect(Wrapper client)
{
if (OnConnect != null)
OnConnect(client);
}
public void InvokeOnReceive(byte[] buffer, int length, Wrapper client)
{
if (OnReceive != null)
OnReceive(buffer, length, client);
}
public void InvokeOnDisconnect(Wrapper client)
{
if (!client.IsAlive) return;
if (OnDisconnect != null)
OnDisconnect(client);
}
}
}
PHP Code:
using System;
using System.Net;
using System.Text;
using System.Linq;
using System.Net.Sockets;
using System.Threading.Tasks;
using System.Collections.Generic;
using System.Runtime.InteropServices;
namespace PureConquer.Network.ServerSocket
{
public class Wrapper
{
public Socket Socket { get; private set; }
public SocketServer Server { get; private set; }
public IPEndPoint RemoteEndPoint { get; private set; }
private readonly byte[] _buffer;
public object Owner;
public Boolean IsAlive { get { return Socket.Connected; } }
public String IP
{
get
{
if (Socket != null)
return (Socket.RemoteEndPoint as IPEndPoint).Address.ToString();
else
return null;
}
}
public Wrapper(SocketServer server, Socket socket, int bufferLength)
{
Server = server;
Socket = socket;
_buffer = new byte[bufferLength];
RemoteEndPoint = (IPEndPoint)Socket.RemoteEndPoint;
Socket.NoDelay = true;
}
public void BeginReceive()
{
try
{
Socket.BeginReceive(_buffer, 0, _buffer.Length, SocketFlags.None, new AsyncCallback(Receive), null);
}
catch (SocketException)
{
Server.InvokeOnDisconnect(this);
}
}
private void Receive(IAsyncResult result)
{
if (Socket != null)
{
try
{
SocketError error;
int length = Socket.EndReceive(result, out error);
if (IsAlive && error == SocketError.Success)
{
if (length > 0)
{
try
{
Server.InvokeOnReceive(_buffer, length, this);
}
catch (Exception e)
{
Console.WriteLine(e.ToString());
}
finally
{
BeginReceive();
}
}
else
{
Server.InvokeOnDisconnect(this);
}
}
}
catch (SocketException)
{
Server.InvokeOnDisconnect(this);
}
}
}
public void Send(byte[] packet)
{
if (IsAlive)
{
try
{
Socket.Send(packet, 0, packet.Length, SocketFlags.None);
}
catch (SocketException)
{
Server.InvokeOnDisconnect(this);
}
}
}
private void EndSend(IAsyncResult result)
{
try
{
Socket.EndSend(result);
}
catch (SocketException)
{
Server.InvokeOnDisconnect(this);
}
}
public void Disconnect()
{
try
{
Socket.Disconnect(false);
}
catch (SocketException)
{
}
Server.InvokeOnDisconnect(this);
}
public override string ToString()
{
return RemoteEndPoint.ToString();
}
}
}
|
|
|
05/18/2017, 05:07
|
#4
|
elite*gold: 12
Join Date: Jul 2011
Posts: 8,282
Received Thanks: 4,191
|
Can you post more of the receive logic?
What's your client buffer length?
Do you have any parallelism outside of the async socket thread pool?
|
|
|
05/20/2017, 23:49
|
#5
|
elite*gold: 0
Join Date: Sep 2014
Posts: 194
Received Thanks: 52
|
Quote:
Originally Posted by Spirited
Can you post more of the receive logic?
|
PHP Code:
static void AuthServer_OnClientReceive(byte[] buffer, Wrapper arg3)
{
var player = arg3.Connector as Client.AuthClient;
player.Cryptographer.Decrypt(buffer, buffer.Length);
player.Queue.Enqueue(buffer, buffer.Length);
while (player.Queue.CanDequeue())
{
byte[] packet = player.Queue.Dequeue();
ushort len = BitConverter.ToUInt16(packet, 0);
ushort id = BitConverter.ToUInt16(packet, 2);
if (len == 312)
{
player.Info = MsgAccountSRP6Ex.Deserialize(packet);
player.Account = new AccountTable(player.Info.Username);
if (!player.Account.exists || (player.Account.exists && player.Account.Password != player.Info.Password))
{
player.Send(MsgConnectEx.Rejected(MsgConnectEx.RejectionCode.InvalidInfo));
return;
}
if (IPBan.IsBanned(arg3.Socket.IP) || player.Account.State == AccountTable.AccountState.Banned)
{
player.Send(MsgConnectEx.Rejected(MsgConnectEx.RejectionCode.Banned));
return;
}
if (player.Account.Password == player.Info.Password && player.Account.exists)
{
var idF = player.Account.GenerateKey();
Kernel.AwaitingPool[idF] = player.Account;
player.Send(MsgConnectEx.Verified(idF, Program.GameIP, Program.GamePort));
return;
}
}
}
}
static void AuthServer_OnClientDisconnect(Wrapper obj)
{
obj.Socket.Disconnect();
}
static void AuthServer_OnClientConnect(Wrapper obj)
{
Client.AuthClient authState;
obj.Connector = (authState = new Client.AuthClient(obj.Socket));
authState.Cryptographer = new Network.Cryptography.AuthCryptography();
authState.Send(MsgEncryptCode.Login((uint)Kernel.Random.Next()));
}
Quote:
|
What's your client buffer length?
|
4048
Quote:
|
Do you have any parallelism outside of the async socket thread pool?
|
No
|
|
|
05/21/2017, 00:14
|
#6
|
elite*gold: 0
Join Date: Apr 2014
Posts: 117
Received Thanks: 91
|
I read somewhere that the socket system used in redux is flawed I don't know if you are using it or what's the problem with it since I didn't really touch it but yeah , you may want to use a different socket system or fix the flaws whatever they are.
|
|
|
05/21/2017, 01:56
|
#7
|
elite*gold: 12
Join Date: Jul 2011
Posts: 8,282
Received Thanks: 4,191
|
Hard to say without walking the code. Those client queues are very suspicious to me.
What happens when you use the sockets from Phoenix only?
|
|
|
05/21/2017, 02:19
|
#8
|
elite*gold: 0
Join Date: Jul 2009
Posts: 943
Received Thanks: 408
|
Quote:
Originally Posted by Spirited
Hard to say without walking the code. Those client queues are very suspicious to me.
What happens when you use the sockets from Phoenix only?
|
My server with Phoenix Socket never had RAM usage issues because of online players amount, it didn't change much from 0 to 100 players.
|
|
|
05/21/2017, 17:09
|
#9
|
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
|
Yeah, that queue looks suspicious, also maybe if you are using unmanaged code in your cipher you might be leaking memory? These are just shots in the dark though.
|
|
|
05/21/2017, 18:15
|
#10
|
elite*gold: 0
Join Date: Sep 2014
Posts: 194
Received Thanks: 52
|
Quote:
Originally Posted by KraHen
Yeah, that queue looks suspicious, also maybe if you are using unmanaged code in your cipher you might be leaking memory? These are just shots in the dark though.
|
i'm using co2_core_dll of cptsky's and when i memory profiled it i saw that something called biginteger uses a huge memory but i think it's get collected by the GC, so i never bothered but idk honestly but reading the comments the socket system seems to be fine.
|
|
|
 |
Similar Threads
|
crap edit do not bother wasting time looking at
05/20/2007 - CO2 Guides & Templates - 8 Replies
anyways here is my first attempt at editing at spell and yes i know i went a bit mad with the editing the ss but its still good xD
Blue lines nado xD
http://i172.photobucket.com/albums/w2/Jaspermanpi cs/bluelined.jpg
|
Why bother anymore?
01/12/2007 - Conquer Online 2 - 13 Replies
Not trying to just complain, but why bother anymore writing anything for CO? It's doomed, the game is made only for those that pay, so unless you have a way to hack money or dup items (both server based and something I have been trying to figure out a way around by packet spoofing with no luck), I just don't see the point anymore. I figure in another couple of months it will be closed up anyway, better off using my time on other projects. Thoughts?
|
Y does bot bother people so much?
12/11/2006 - Conquer Online 2 - 3 Replies
Yes but we really do find it funyn that the only people who actually want the bots are the people with like 20 posts/0 karma...and probably dont even know how to play conquer properly ^^ the rest of us realise that COpartner has ruined the game. And while im on a roll i would like to add that some of us dont really care about the bots but the select few people we actually like and we are here for the community rather than the freebies. Kthnxbai
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...
|
All times are GMT +1. The time now is 09:34.
|
|