|
You last visited: Today at 06:59
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/20/2014, 19:44
|
#1
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
|
[Server, Client and socket] unkown problem i can't fix
in explanation of my problem i have a client and server apps
server send and receive packet as client do ...
the client sends a login request to the server and if server replied with agree
the main form of client shall be hide and appear another form for the user ..
everything is okay ...
but when i send a packet from the server to the client while user is logged on ... the client don't receive it until the user log out and client went back to the main form
but client send packets any time normally and server receive it as well ..
so any solution ?
Server :
PHP Code:
private void Open_Hash_Minutes_Click(object sender, EventArgs e) { if (SelectedClient.PC_STATE == Data.Enums.ClientState.Reachable || SelectedClient.PC_STATE == Data.Enums.ClientState.Online) { Control control = (Control)sender; int Time = int.Parse(control.Text); SetTimeForm LF = new SetTimeForm(SelectedClient, Calc, Time); DialogResult dr = LF.ShowDialog(this); if (dr == System.Windows.Forms.DialogResult.Cancel) { LF.Close(); } else if (dr == System.Windows.Forms.DialogResult.OK) { if (SelectedClient.PC_STATE == Data.Enums.ClientState.Reachable) { Network.Packets.LoginOrder LO = new Network.Packets.LoginOrder(true, true, LF.ChoosedTime, Data.Enums.User.Guest); LO.Send(SelectedClient); } else if (SelectedClient.PC_STATE == Data.Enums.ClientState.Online || SelectedClient.PC_STATE == Data.Enums.ClientState.Paused) { Network.Packets.EditSession EditSession = new Network.Packets.EditSession(true, true, LF.ChoosedTime); SelectedClient.Send(EditSession); } } } else { MessageBox.Show("This client is not reachable !", "HotCafe Server", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
PHP Code:
static void AuthServer_AnnounceNewConnection(Interfaces.ISocketWrapper obj) { Client.State authState = new Client.State(obj.Socket); obj.Connector = authState; } static void AuthServer_AnnounceDisconnection(Interfaces.ISocketWrapper obj) { if (obj != null) { Client.State client = (Client.State)obj.Connector; if (client != null) { client.Disconnect(); } } } static void AuthServer_AnnounceReceive(byte[] packet, Interfaces.ISocketWrapper StO) { try { Client.State client = (Client.State)StO.Connector; client.MF = MF; Network.PacketHandler.Handle(packet, client); } catch (Exception e) { Program.WriteLine(e.ToString()); } }
Client :
PHP Code:
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 void LogIn(Client.State _client) { switch (client.PC_USER) { case Data.Enums.ClientUser.Admin: { //this.Hide(); OldSize = this.Size; this.Size = new System.Drawing.Size(0, 0); this.WindowState = FormWindowState.Minimized; 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(); OldSize = this.Size; this.Size = new System.Drawing.Size(0, 0); this.WindowState = FormWindowState.Minimized; HandForm = new HandForm(this, client); HandForm.UserForm.AdminControlIsVisible = false; HandForm.UserForm.UpdateStart(); HandForm.ShowDialog(this); break; } case false: { //this.Hide(); OldSize = this.Size; this.Size = new System.Drawing.Size(0, 0); this.WindowState = FormWindowState.Minimized; HandForm = new HandForm(this, client); HandForm.UserForm.AdminControlIsVisible = false; HandForm.UserForm.UpdateStart(); HandForm.ShowDialog(this); break; } } break; } } }
i break pointed handle void in client , but it's don't receive the packet until session is ended
|
|
|
10/20/2014, 19:49
|
#2
|
elite*gold: 67
Join Date: Aug 2014
Posts: 1,321
Received Thanks: 927
|
Atleast show us the code.
|
|
|
10/20/2014, 19:55
|
#3
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
|
what exactly code you want to check ?
i tried to don't hide the main form and just re size it to (0, 0) and minimize it but still my problem is going up ...
|
|
|
10/20/2014, 20:10
|
#4
|
elite*gold: 0
Join Date: Jul 2014
Posts: 402
Received Thanks: 540
|
|
|
|
10/20/2014, 20:19
|
#5
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
|
Server :
PHP Code:
private void Open_Hash_Minutes_Click(object sender, EventArgs e) { if (SelectedClient.PC_STATE == Data.Enums.ClientState.Reachable || SelectedClient.PC_STATE == Data.Enums.ClientState.Online) { Control control = (Control)sender; int Time = int.Parse(control.Text); SetTimeForm LF = new SetTimeForm(SelectedClient, Calc, Time); DialogResult dr = LF.ShowDialog(this); if (dr == System.Windows.Forms.DialogResult.Cancel) { LF.Close(); } else if (dr == System.Windows.Forms.DialogResult.OK) { if (SelectedClient.PC_STATE == Data.Enums.ClientState.Reachable) { Network.Packets.LoginOrder LO = new Network.Packets.LoginOrder(true, true, LF.ChoosedTime, Data.Enums.User.Guest); LO.Send(SelectedClient); } else if (SelectedClient.PC_STATE == Data.Enums.ClientState.Online || SelectedClient.PC_STATE == Data.Enums.ClientState.Paused) { Network.Packets.EditSession EditSession = new Network.Packets.EditSession(true, true, LF.ChoosedTime); SelectedClient.Send(EditSession); } } } else { MessageBox.Show("This client is not reachable !", "HotCafe Server", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
PHP Code:
static void AuthServer_AnnounceNewConnection(Interfaces.ISocketWrapper obj) { Client.State authState = new Client.State(obj.Socket); obj.Connector = authState; } static void AuthServer_AnnounceDisconnection(Interfaces.ISocketWrapper obj) { if (obj != null) { Client.State client = (Client.State)obj.Connector; if (client != null) { client.Disconnect(); } } } static void AuthServer_AnnounceReceive(byte[] packet, Interfaces.ISocketWrapper StO) { try { Client.State client = (Client.State)StO.Connector; client.MF = MF; Network.PacketHandler.Handle(packet, client); } catch (Exception e) { Program.WriteLine(e.ToString()); } }
Client :
PHP Code:
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 void LogIn(Client.State _client) { switch (client.PC_USER) { case Data.Enums.ClientUser.Admin: { //this.Hide(); OldSize = this.Size; this.Size = new System.Drawing.Size(0, 0); this.WindowState = FormWindowState.Minimized; 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(); OldSize = this.Size; this.Size = new System.Drawing.Size(0, 0); this.WindowState = FormWindowState.Minimized; HandForm = new HandForm(this, client); HandForm.UserForm.AdminControlIsVisible = false; HandForm.UserForm.UpdateStart(); HandForm.ShowDialog(this); break; } case false: { //this.Hide(); OldSize = this.Size; this.Size = new System.Drawing.Size(0, 0); this.WindowState = FormWindowState.Minimized; HandForm = new HandForm(this, client); HandForm.UserForm.AdminControlIsVisible = false; HandForm.UserForm.UpdateStart(); HandForm.ShowDialog(this); break; } } break; } } }
i break pointed handle void in client , but it's don't receive the packet until session is ended
|
|
|
10/20/2014, 20:27
|
#6
|
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 946
|
I would help you if I could read your ******* code.
|
|
|
10/20/2014, 20:48
|
#7
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
|
Quote:
Originally Posted by Super Aids
I would help you if I could read your ******* code.
|
isn't hard to read my great code lol
just tell me what point you can't get ...
|
|
|
10/20/2014, 21:45
|
#8
|
elite*gold: 21
Join Date: Jul 2005
Posts: 9,193
Received Thanks: 5,376
|
Quote:
Originally Posted by abdeen
isn't hard to read my great code lol
just tell me what point you can't get ...
|
it's a useless mess like everything you post here.
Stop, just stop.
|
|
|
10/20/2014, 21:56
|
#9
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
|
Quote:
Originally Posted by pro4never
it's a useless mess like everything you post here.
Stop, just stop.
|
post a solution or Stop , just stop.
|
|
|
10/20/2014, 23:21
|
#10
|
elite*gold: 67
Join Date: Aug 2014
Posts: 1,321
Received Thanks: 927
|
He has a point you know? Halloween isnt for another 11 days but your code looks spooky already. Take my candy, just take it and make it stop.
|
|
|
10/20/2014, 23:50
|
#11
|
elite*gold: 0
Join Date: Dec 2012
Posts: 1,761
Received Thanks: 946
|
I don't understand anything.
What about learning the language and name conventions.
|
|
|
10/21/2014, 18:52
|
#12
|
elite*gold: 0
Join Date: Jul 2008
Posts: 874
Received Thanks: 239
|
offtopic:
try this
may be it help you in ur coding.
-----
posting the codes make it worse.
try to organize the codes and more information
and try to breakpoints the handling
|
|
|
10/21/2014, 21:09
|
#13
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
|
Quote:
Originally Posted by abdoumatrix
offtopic:
try this
may be it help you in ur coding.
-----
posting the codes make it worse.
try to organize the codes and more information
and try to breakpoints the handling
|
i am already posted the codes ...
but as i explained the issue it's with forms .. client do no accept packets until i went back to the main form ... and i will put here an code for for explanation ...
client Side [ MainForm.cs ]:
PHP Code:
public partial class MainCafeForm : Form { public Data.Calculator Calc; public MainCafeForm() { InitializeComponent(); CheckForIllegalCrossThreadCalls = false; } private void MainForm_Load(object sender, EventArgs e) { BGW.RunWorkerAsync(); Calc = new Data.Calculator(); } private void BGW_DoWork(object sender, DoWorkEventArgs e) { Program.StartEngine(); } #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(); FlashWallpaper.Movie = Application.StartupPath + @"\Paused.swf"; FlashWallpaper.Play(); this.HandForm.Close(); } public void Resume(Client.State _client) { } public void LogOut(Client.State _client) { this.LoginTimer.Stop(); this.Show(); this.HandForm.Close(); } #endregion }
[ Session.cs ]
PHP Code:
public class Session { System.Windows.Forms.Timer SystemTimer = new System.Windows.Forms.Timer(); public bool Limited { get; set; } public int Minutes { get; set; } Data.Enums.ClientUser USER_TYPE { get; set; } public DateTime TimeStart; public DateTime TimeEnd; Client.State client; public Session(Client.State _client, Network.Packets.StartSession StartSession) { this.client = _client; var dat = DateTime.Now; Limited = StartSession.Limited; Minutes = StartSession.Time; USER_TYPE = StartSession.USER_TYPE; TimeStart = dat; TimeEnd = TimeStart.AddMinutes(Minutes); SystemTimer.Interval = 1000; SystemTimer.Tick += new EventHandler(SystemTimer_Tick); } public void Start() { this.client.StatusHandler = new StatusHandler(this.client); this.client.SessionStatus = Enums.Session.Started; this.client.ClientState = Enums.ClientState.Online; this.client.PC_START_TIME = TimeStart.ToString("hh:mm:ss tt"); this.client.PC_USER = USER_TYPE; Network.Packets.ClientState ClientState = new Network.Packets.ClientState(true, this.client.ClientState); this.client.Send(ClientState); this.client.StatusHandler.Start(); this.SystemTimer.Start(); this.client.MF.LogIn(this.client); } public void Pause() { TimeSpan ts = DateTime.Now - TimeStart; Minutes = Minutes - ts.Minutes; this.client.SessionStatus = Enums.Session.Paused; this.client.ClientState = Enums.ClientState.Paused; Network.Packets.ClientState ClientState = new Network.Packets.ClientState(true, this.client.ClientState); this.client.Send(ClientState); this.client.MF.Pause(this.client); this.SystemTimer.Stop(); } public void Resume() { this.client.SessionStatus = Enums.Session.Resumed; this.client.ClientState = Enums.ClientState.Online; Network.Packets.ClientState ClientState = new Network.Packets.ClientState(true, this.client.ClientState); this.client.Send(ClientState); this.client.MF.Resume(this.client); this.SystemTimer.Start(); } public void End() { this.client.SessionStatus = Enums.Session.Ended; this.client.ClientState = Enums.ClientState.Reachable; Network.Packets.ClientState ClientState = new Network.Packets.ClientState(true, this.client.ClientState); this.client.Send(ClientState); this.client.MF.LogOut(this.client); this.client = null; this.SystemTimer.Stop(); } private void SystemTimer_Tick(object sender, EventArgs e) { if (client.SessionStatus == Enums.Session.Started) { if (this.client.PC_USER == Enums.ClientUser.Guest) { if (this.Limited) { if (DateTime.Now >= TimeStart.AddMinutes(Minutes)) { End(); } } } } } internal void Edit(bool Add, int Time) { if (Add) { Minutes += Time; } else { Minutes -= Time; } } }
[ PacketHandler.cs ]
PHP Code:
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; } } }
[ Program.cs ]
PHP Code:
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()); } 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()); } } }
[ UserForm.cs ]
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(); this.MF.Features.End(); this.UserFormLabel.Text = client.PC_HOST; Network.Packets.Update Update = new Network.Packets.Update(true); Update.Type = Network.Packets.Update.StartTime; string Time; if (client.PC_START_TIME.Contains("م")) { Time = client.PC_START_TIME.Replace("م", "PM"); } else if (client.PC_START_TIME.Contains("ص")) { Time = client.PC_START_TIME.Replace("ص", "AM"); } else { Time = client.PC_START_TIME; } Update.STRING_Value = Time; client.Send(Update); } }
|
|
|
10/21/2014, 21:24
|
#14
|
elite*gold: 130
Join Date: Oct 2007
Posts: 1,652
Received Thanks: 701
|
Enviremont.Exit(0);
|
|
|
10/21/2014, 21:39
|
#15
|
elite*gold: 0
Join Date: Mar 2010
Posts: 475
Received Thanks: 14
|
Quote:
Originally Posted by turk55
Enviremont.Exit(0);
|
this for quit the app .... did you read my issue ?
|
|
|
|
|
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 06:59.
|
|