|
You last visited: Today at 02:03
Advertisement
[Server, Client and socket] unkown problem i can't fix
Discussion on [Server, Client and socket] unkown problem i can't fix within the CO2 Programming forum part of the Conquer Online 2 category.
10/21/2014, 22:00
|
#16
|
elite*gold: 130
Join Date: Oct 2007
Posts: 1,655
Received Thanks: 706
|
Quote:
Originally Posted by abdeen
this for quit the app .... did you read my issue ?
|
Yes and also your other posts.
|
|
|
10/21/2014, 22:09
|
#17
|
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 239
|
Quote:
Originally Posted by abdeen
PHP Code:
private void BGW_DoWork(object sender, DoWorkEventArgs e) { Program.StartEngine(); }
|
and these ??
|
|
|
10/21/2014, 22:11
|
#18
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,383
|
Quote:
Originally Posted by abdeen
this for quit the app .... did you read my issue ?
|
We're reminding you again that you should not be posting.
Seriously, **** off.
|
|
|
10/21/2014, 23:33
|
#19
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
|
Quote:
Originally Posted by abdoumatrix
and these ??
|
what about this back ground worker ?
the issue is when i send a packet to the client when the session is started the client dont receive it till the session is end and when i break pointed the coming packet in the client i kept press F10 till the last line and its give me this screen ...
|
|
|
10/22/2014, 01:58
|
#20
|
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
|
Okay, who paid the clown? Seriously guys, it`s much appreciated.
|
|
|
10/22/2014, 08:43
|
#21
|
elite*gold: 0
Join Date: Jan 2007
Posts: 485
Received Thanks: 272
|
Quote:
Originally Posted by abdeen
what about this back ground worker ?
the issue is when i send a packet to the client when the session is started the client dont receive it till the session is end and when i break pointed the coming packet in the client i kept press F10 till the last line and its give me this screen ...
|
You know, sometimes you need to step into, not step over. Like when you see a **** lying down, in order to check it out, step into it, don't step over it, or you might miss to see that that's a real ****.
|
|
|
10/22/2014, 09:39
|
#22
|
elite*gold: 0
Join Date: Jun 2014
Posts: 65
Received Thanks: 2
|
Quote:
Originally Posted by donn
You know, sometimes you need to step into, not step over. Like when you see a **** lying down, in order to check it out, step into it, don't step over it, or you might miss to see that that's a real ****.
|
i died there, ty donn making my day.
|
|
|
10/22/2014, 09:49
|
#23
|
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 950
|
Quote:
Originally Posted by donn
You know, sometimes you need to step into, not step over. Like when you see a **** lying down, in order to check it out, step into it, don't step over it, or you might miss to see that that's a real ****.
|
It's funny, because it's pretty much how debugging works.
|
|
|
10/24/2014, 00:12
|
#24
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
|
Okay guys i tried to comment out this code
PHP Code:
HandForm = new HandForm(this, client);
HandForm.UserForm.AdminControlIsVisible = false;
HandForm.UserForm.UpdateStart();
HandForm.ShowDialog(this);
it's a part of this
PHP Code:
case Data.Enums.ClientUser.Guest:
{
switch (client.Session.Limited)
{
case true:
{
this.Hide();
HandForm = new HandForm(this, client);
HandForm.UserForm.AdminControlIsVisible = false;
HandForm.UserForm.UpdateStart();
HandForm.ShowDialog(this);
break;
}
case false:
{
this.Hide();
HandForm = new HandForm(this, client);
HandForm.UserForm.AdminControlIsVisible = false;
HandForm.UserForm.UpdateStart();
HandForm.ShowDialog(this);
break;
}
}
break;
}
and i kept on trying Un-comment the lines on by one till the last one when i tried it i got the problem is here when i show the handform
PHP Code:
HandForm.ShowDialog(this);
Client Socket :
PHP Code:
public class AsyncSocket
{
public Socket Connection, HashSocket;
public event Action<AsyncSocketWrapper> OnClientConnect;
public event Action<AsyncSocketWrapper> OnClientDisconnect;
public event Action<byte[], AsyncSocketWrapper> OnClientReceive;
public AsyncSocket()
{
Connection = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
HashSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
}
public bool Connect(string IP, int Port)
{
IPAddress ipAddress = IPAddress.Parse(IP);
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, Port);
while (!Connection.Connected)
{
try
{
HashSocket.Connect(ipEndPoint);
if (HashSocket.Connected)
{
Connection.BeginConnect(ipEndPoint, new AsyncCallback(AsyncConnect), null);
System.Threading.Thread.Sleep(2000);
if (Connection.Connected)
{
return true;
}
}
}
catch
{
System.Threading.Thread.Sleep(2000);
}
}
return false;
}
private void AsyncConnect(IAsyncResult res)
{
try
{
AsyncSocketWrapper sender = null;
sender = new AsyncSocketWrapper();
sender.BufferSize = 8000;
sender.Socket = this.Connection;
sender.Buffer = new byte[sender.BufferSize];
this.Connection.EndConnect(res);
if (this.OnClientConnect != null)
{
this.OnClientConnect(sender);
}
sender.Socket.BeginReceive(sender.Buffer, 0, sender.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), sender);
}
catch (Exception ex)
{
Program.WriteLine(ex);
}
}
private void OnSend(IAsyncResult res)
{
try
{
Connection.EndSend(res);
byte[] byteData = new byte[1024];
Connection.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(AsyncReceive), null);
}
catch (Exception ex)
{
Program.WriteLine(ex);
}
}
private void AsyncReceive(IAsyncResult res)
{
bool was = false;
try
{
SocketError error;
AsyncSocketWrapper asyncState = (AsyncSocketWrapper)res.AsyncState;
int RecvSize = asyncState.Socket.EndReceive(res, out error);
if ((error == SocketError.Success) && (RecvSize > 0))
{
was = true;
byte[] buffer = new byte[RecvSize];
for (int i = 0; i < RecvSize; i++)
{
buffer[i] = asyncState.Buffer[i];
}
if (this.OnClientReceive != null)
{
this.OnClientReceive(buffer, asyncState);
}
asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState);
}
else
{
this.InvokeDisconnect(asyncState);
}
}
catch (SocketException e)
{
Program.WriteLine(e);
if (was)
{
AsyncSocketWrapper asyncState = (AsyncSocketWrapper)res.AsyncState;
asyncState.Socket.BeginReceive(asyncState.Buffer, 0, asyncState.Buffer.Length, SocketFlags.None, new AsyncCallback(this.AsyncReceive), asyncState);
}
}
catch (ObjectDisposedException e)
{
Program.WriteLine(e);
}
catch (Exception ex)
{
Program.WriteLine(ex);
}
}
public void InvokeDisconnect(AsyncSocketWrapper Client)
{
if (Client != null)
{
try
{
if (Client.Socket.Connected)
{
Client.Socket.Shutdown(SocketShutdown.Both);
Client.Socket.Close();
if (this.OnClientDisconnect != null)
{
this.OnClientDisconnect(Client);
}
Client.Connector = null;
Client = null;
}
else
{
if (this.OnClientDisconnect != null)
{
this.OnClientDisconnect(Client);
}
Client.Connector = null;
Client = null;
}
}
catch (ObjectDisposedException e)
{
Program.WriteLine(e);
}
}
}
}
class Program
{
static MainForm MF;
public static Network.Sockets.AsyncSocket AuthServer;
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(MF = new MainForm());
}
public static void StartEngine()
{
AuthServer = new AsyncSocket();
AuthServer.OnClientConnect += new Action<AsyncSocketWrapper>(AuthServer_AnnounceNewConnection);
AuthServer.OnClientReceive += new Action<byte[], AsyncSocketWrapper>(AuthServer_AnnounceReceive);
AuthServer.OnClientDisconnect += new Action<AsyncSocketWrapper>(AuthServer_AnnounceDisconnection);
if (AuthServer.Connect("192.168.1.100", 9958))
{
GC.Collect();
}
}
public static void WriteLine(string Text)
{
//MF.WriteLine(Text);
}
public static void WriteLine(Exception Text)
{
//MF.WriteLine(Text.Message);
}
public static void WriteLine(uint Text)
{
//MF.WriteLine(Text.ToString());
}
static void AuthServer_AnnounceNewConnection(AsyncSocketWrapper obj)
{
Client.State client = new Client.State(obj.Socket, MF);
obj.Connector = client;
if (MF.client == null)
{
MF.client = client;
}
Network.Packets.ComputerInformation ComputerInformation = new Network.Packets.ComputerInformation(true, client);
ComputerInformation.Send(client);
}
static void AuthServer_AnnounceDisconnection(AsyncSocketWrapper obj)
{
if (obj != null)
{
Client.State client = (Client.State)obj.Connector;
if (client != null)
{
client.Reconnect();
}
}
}
static void AuthServer_AnnounceReceive(byte[] packet, AsyncSocketWrapper obj)
{
try
{
Client.State client = (Client.State)obj.Connector;
Network.PacketHandler.Handle(packet, client);
}
catch (Exception e)
{
Program.WriteLine(e.ToString());
}
}
}
public static void Handle(byte[] packet, Client.State client)
{
if (packet == null)
return;
if (client == null)
return;
ushort ID = BitConverter.ToUInt16(packet, 0);
ushort Length = BitConverter.ToUInt16(packet, 2);
switch (ID)
{
case 1003:
{
Message message = new Message();
message.Deserialize(packet);
if (message.MESSAGE_CONTENT.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries).Length > 0)
message.MESSAGE_CONTENT = message.MESSAGE_CONTENT.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries)[0];
Chat(message, client);
break;
}
case 1005:
{
Network.Packets.StartSession StartSession = new Network.Packets.StartSession();
StartSession.Deserialize(packet);
client.Session = new Data.Session(client, StartSession);
client.Session.Start();
break;
}
case 1007:
{
Network.Packets.EditSession EditSession = new Network.Packets.EditSession();
EditSession.Deserialize(packet);
client.Session.Edit(EditSession.Add, EditSession.Time);
break;
}
default:
{
client.Send(packet);
break;
}
}
}
PHP Code:
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
CheckForIllegalCrossThreadCalls = false;
}
public Client.State client;
public HandForm HandForm;
private void BGW_DoWork(object sender, DoWorkEventArgs e)
{
Program.StartEngine();
}
#region Form Load / Close
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
}
private void MainForm_Load(object sender, EventArgs e)
{
FlashWallpaper.Play();
BGW.RunWorkerAsync();
}
#endregion
#region Session Handle
public void LogIn(Client.State _client)
{
switch (client.PC_USER)
{
case Data.Enums.ClientUser.Admin:
{
this.Hide();
HandForm = new HandForm(this, client);
HandForm.UserForm.AdminControlIsVisible = true;
HandForm.UserForm.UpdateStart();
HandForm.ShowDialog(this);
}
break;
case Data.Enums.ClientUser.Guest:
{
switch (client.Session.Limited)
{
case true:
{
this.Hide();
HandForm = new HandForm(this, client);
HandForm.UserForm.AdminControlIsVisible = false;
HandForm.UserForm.UpdateStart();
HandForm.ShowDialog(this);
break;
}
case false:
{
this.Hide();
HandForm = new HandForm(this, client);
HandForm.UserForm.AdminControlIsVisible = false;
HandForm.UserForm.UpdateStart();
HandForm.ShowDialog(this);
break;
}
}
break;
}
}
}
public void Pause(Client.State _client)
{
this.LoginTimer.Stop();
this.Show();
this.HandForm.Close();
}
public void Resume(Client.State _client)
{
}
public void LogOut(Client.State _client)
{
this.LoginTimer.Stop();
this.Show();
this.HandForm.Close();
}
#endregion
}
PHP Code:
public partial class HandForm : Form
{
public UserForm UserForm;
public MainForm MainForm;
public Client.State client;
bool Opened = false;
SlidingController slider = null;
public HandForm(MainForm mainForm, Client.State client)
{
InitializeComponent();
this.MainForm = mainForm;
this.client = client;
UserForm = new UserForm(mainForm, client);
slider = new SlidingController(UserForm, this);
}
private void HandForm_Load(object sender, EventArgs e)
{
UserForm.Show();
slider.Initialize();
}
private void HandForm_MouseClick(object sender, MouseEventArgs e)
{
if (e.Button == System.Windows.Forms.MouseButtons.Left)
{
if (Opened)
{
slider.DrawUndraw();
this.BackgroundImage = HotCafe_Client.Properties.Resources.Show;
Opened = false;
}
else
{
slider.DrawUndraw();
this.BackgroundImage = HotCafe_Client.Properties.Resources.Hide;
Opened = true;
}
}
}
private void HandForm_FormClosing(object sender, FormClosingEventArgs e)
{
UserForm.Close();
}
}
PHP Code:
public partial class UserForm : Form
{
private Client.State client;
private MainForm MF;
public UserForm(MainForm mainForm, Client.State client)
{
this.MF = mainForm;
this.client = client;
InitializeComponent();
}
public bool AdminControlIsVisible
{
set { this.Exit_Key.Enabled = value; this.Options_Key.Enabled = value; }
}
private void Options_Key_Click(object sender, EventArgs e)
{
client.Session.Pause();
}
private void Exit_Key_Click(object sender, EventArgs e)
{
}
private void Logout_Key_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure that you want to end the session ?", "HotCafe", MessageBoxButtons.YesNo, MessageBoxIcon.Question ) == System.Windows.Forms.DialogResult.Yes)
{
client.Session.End();
}
}
}
}
i got it i can receive the packets even if i hided the main form but it's not receiving packet when i show the hand form ...
and i can receive all packets which are sent by server when the session is ended and hand form is closed ...
is it clear enough ?
|
|
|
10/24/2014, 11:53
|
#25
|
elite*gold: 67
Join Date: Aug 2014
Posts: 1,323
Received Thanks: 928
|
Quote:
|
i got it i can receive the packets even if i hided the main form but it's not receiving packet when i show the hand form ...
|
Also: Nice job at copying the Codeproject signature into yours lol.
|
|
|
10/24/2014, 12:12
|
#26
|
elite*gold: 0
Join Date: Jan 2007
Posts: 485
Received Thanks: 272
|
Am I wrong or showing a modal dialog freezes the thread that calls it till the dialog is closed?
|
|
|
10/24/2014, 16:48
|
#27
|
elite*gold: 0
Join Date: Jul 2006
Posts: 2,216
Received Thanks: 794
|
Quote:
Originally Posted by donn
Am I wrong or showing a modal dialog freezes the thread that calls it till the dialog is closed?
|
No, ShowDialog indeed blocks the thread from which it is called.
|
|
|
10/24/2014, 17:43
|
#28
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 15
|
Quote:
Originally Posted by KraHen
No, ShowDialog indeed blocks the thread from which it is called.
|
so how to fix it keeping it receive packet if i am showing multiple winforms ?
Program.cs
PHP Code:
class Program
{
static MainForm MF;
public static Network.Sockets.AsyncSocket AuthServer;
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(MF = new MainForm());
}
public static void StartEngine()
{
AuthServer = new AsyncSocket();
AuthServer.OnClientConnect += new Action<AsyncSocketWrapper>(AuthServer_AnnounceNewConnection);
AuthServer.OnClientReceive += new Action<byte[], AsyncSocketWrapper>(AuthServer_AnnounceReceive);
AuthServer.OnClientDisconnect += new Action<AsyncSocketWrapper>(AuthServer_AnnounceDisconnection);
if (AuthServer.Connect("192.168.1.100", 9958))
{
GC.Collect();
}
}
public static void WriteLine(string Text)
{
//MF.WriteLine(Text);
}
public static void WriteLine(Exception Text)
{
//MF.WriteLine(Text.Message);
}
public static void WriteLine(uint Text)
{
//MF.WriteLine(Text.ToString());
}
static void AuthServer_AnnounceNewConnection(AsyncSocketWrapper obj)
{
Client.State client = new Client.State(obj.Socket, MF);
obj.Connector = client;
if (MF.client == null)
{
MF.client = client;
}
Network.Packets.ComputerInformation ComputerInformation = new Network.Packets.ComputerInformation(true, client);
ComputerInformation.Send(client);
}
static void AuthServer_AnnounceDisconnection(AsyncSocketWrapper obj)
{
if (obj != null)
{
Client.State client = (Client.State)obj.Connector;
if (client != null)
{
client.Reconnect();
}
}
}
static void AuthServer_AnnounceReceive(byte[] packet, AsyncSocketWrapper obj)
{
try
{
Client.State client = (Client.State)obj.Connector;
Network.PacketHandler.Handle(packet, client);
}
catch (Exception e)
{
Program.WriteLine(e.ToString());
}
}
}
PacketHandler.cs
PHP Code:
public static class PacketHandler
{
public static void Handle(byte[] packet, Client.State client)
{
if (packet == null)
return;
if (client == null)
return;
ushort ID = BitConverter.ToUInt16(packet, 0);
ushort Length = BitConverter.ToUInt16(packet, 2);
switch (ID)
{
case 1003:
{
Message message = new Message();
message.Deserialize(packet);
if (message.MESSAGE_CONTENT.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries).Length > 0)
message.MESSAGE_CONTENT = message.MESSAGE_CONTENT.Split(new string[] { "\\n" }, StringSplitOptions.RemoveEmptyEntries)[0];
Chat(message, client);
break;
}
case 1005:
{
Network.Packets.StartSession StartSession = new Network.Packets.StartSession();
StartSession.Deserialize(packet);
client.Session = new Data.Session(client, StartSession);
client.Session.Start();
break;
}
case 1007:
{
Network.Packets.EditSession EditSession = new Network.Packets.EditSession();
EditSession.Deserialize(packet);
client.Session.Edit(EditSession.Add, EditSession.Time);
break;
}
default:
{
client.Send(packet);
break;
}
}
}
private static void Chat(Message message, Client.State client)
{
switch (message.MESSAGE_TYPE)
{
case Data.Enums.ChatType.System:
{
string M = message.MESSAGE_CONTENT.Replace("\0", "").Split('\0')[0];
switch (M)
{
case "ADMIN_LOGIN_NO":
{
client.MF.UpdateSystemMessage("Invalid Username or Password!!");
break;
}
case "LOGIN_REQUEST_REJECTED":
{
client.MF.UpdateSystemMessage("Login request has been rejected!!");
break;
}
}
break;
}
case Data.Enums.ChatType.Whisper:
{
break;
}
}
}
}
|
|
|
10/24/2014, 19:15
|
#29
|
elite*gold: 0
Join Date: Sep 2007
Posts: 71
Received Thanks: 13
|
abdeen shut the **** up, nobody cares about your problems
|
|
|
10/24/2014, 20:23
|
#30
|
elite*gold: 0
Join Date: Jul 2014
Posts: 402
Received Thanks: 540
|
Quote:
Originally Posted by abdeen
PHP Code:
if (AuthServer.Connect("192.168.1.100", 9958))
{
GC.Collect();
}
|
Please, abdeen, stop yourself.
|
|
|
 |
|
Similar Threads
|
Client check if server socket is open C#
10/21/2014 - CO2 Programming - 5 Replies
i want the client check if the server socket is online or not , and if it's not it's wait 20 sec then check again .. i tried to figure it out by making this code but still doesn't make what i want ... i think there is a good solution better than the one i made .
public bool Connect(string IP, int Port)
{
int tries = 0;
IPAddress ipAddress = IPAddress.Parse(IP);
IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, Port);
while...
|
Editing Conquer Server Socket [ creating new client ]
04/21/2014 - CO2 Private Server - 11 Replies
Hello Epvp members , as title say i am editing conquer server socket to make it conquer client socket , actually i tried it many times but fails , spent more time on that , well ,, here is my idea..
Server and client each one have 2 sockets... Login Socket , Game Socket
Server socket working very well , but i need to edit it to work with the client , just receiving and sending data , bytes and packets.. and don`t listen for incoming connections ... as i said i spent long time on this i...
|
socket_read() [function.socket-read]: unable to read from socket [0] - Problem
03/10/2012 - Web Development - 0 Replies
Thema gelöst ; )
|
VPC problem - can´t connect to local mySQL server trough socket
07/29/2011 - Metin2 Private Server - 26 Replies
hallo leute wollte mir einen mt2 pserver erstellen hat auch alles geklappt...
metin ist auch gelaufen....
nur mein windows hat ein bisschen gesponnen..
also habe ich es mit service pack 1 auf einer andern festplatte neu aufgesetzt..
dann wollte ich mit vpc wieder einen pserver erstellen
erstellt dann im vpc nach dem login (hab natürlich alles konfiguriert)
wollte ich wie gewoht ./start eingeben aber dann kam folgendes:
http://img713.imageshack.us/img713/4706/startfehl erm.jpg
|
Steelseries Merc Stelth Problem ( Unkown Device )
03/01/2010 - Technical Support - 4 Replies
Hi leute,
meine wundertolle Freundin hat mir das tolle MERC Stealth von Steelseries gekauft.
Leider erkennt mein laptop es weder als Tastatur noch als sonst irgendwas, es wird immer nur "unknown Device" angezeigt. Habs bei ihr aufm Laptop auch probiert, genau das selbe. Alle Treiber und Bios sind geupdated (inklusive chipsätze).
Der Laptop den ich benutz ist ein Acer Aspire 7738G mit Win7 64 bit
Ich hoff ihr könnt mir helfen :)
Grüße
|
All times are GMT +2. The time now is 02:03.
|
|