[Server, Client and socket] unkown problem i can't fix

10/21/2014 22:00 turk55#16
Quote:
Originally Posted by abdeen View Post
this for quit the app .... did you read my issue ?
Yes and also your other posts.
10/21/2014 22:09 abdoumatrix#17
Quote:
Originally Posted by abdeen View Post
PHP Code:
        private void BGW_DoWork(object senderDoWorkEventArgs e)
        {
            
Program.StartEngine();
        } 
and these ??
10/21/2014 22:11 pro4never#18
Quote:
Originally Posted by abdeen View Post
this for quit the app .... did you read my issue ?
We're reminding you again that you should not be posting.

Seriously, fuck off.
10/21/2014 23:33 abdeen#19
Quote:
Originally Posted by abdoumatrix View Post
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 ...

[Only registered and activated users can see links. Click Here To Register...]
10/22/2014 01:58 KraHen#20
Okay, who paid the clown? Seriously guys, it`s much appreciated.
10/22/2014 08:43 donn#21
Quote:
Originally Posted by abdeen View Post
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 shit 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 shit.
10/22/2014 09:39 HMusic#22
Quote:
Originally Posted by donn View Post
You know, sometimes you need to step into, not step over. Like when you see a shit 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 shit.
i died there, ty donn making my day.
10/22/2014 09:49 Super Aids#23
Quote:
Originally Posted by donn View Post
You know, sometimes you need to step into, not step over. Like when you see a shit 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 shit.
It's funny, because it's pretty much how debugging works.
10/24/2014 00:12 abdeen#24
Okay guys i tried to comment out this code

PHP Code:
                                    HandForm = new HandForm(thisclient);
                                    
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(thisclient);
                                    
HandForm.UserForm.AdminControlIsVisible false;
                                    
HandForm.UserForm.UpdateStart();
                                    
HandForm.ShowDialog(this);
                                    break;
                                }
                            case 
false:
                                {
                                    
this.Hide();
                                    
HandForm = new HandForm(thisclient);
                                    
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 ConnectionHashSocket;
    public 
event Action<AsyncSocketWrapperOnClientConnect;
    public 
event Action<AsyncSocketWrapperOnClientDisconnect;
    public 
event Action<byte[], AsyncSocketWrapperOnClientReceive;

    public 
AsyncSocket()
    {
        
Connection = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
        
HashSocket = new Socket(AddressFamily.InterNetworkSocketType.StreamProtocolType.Tcp);
    }
    public 
bool Connect(string IPint Port)
    {
        
IPAddress ipAddress IPAddress.Parse(IP);
        
IPEndPoint ipEndPoint = new IPEndPoint(ipAddressPort);
        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.Buffer0sender.Buffer.LengthSocketFlags.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(byteData0byteData.LengthSocketFlags.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(resout error);
            if ((
error == SocketError.Success) && (RecvSize 0))
            {
                
was true;
                
byte[] buffer = new byte[RecvSize];
                for (
int i 0RecvSizei++)
                {
                    
buffer[i] = asyncState.Buffer[i];
                }
                if (
this.OnClientReceive != null)
                {
                    
this.OnClientReceive(bufferasyncState);
                }

                
asyncState.Socket.BeginReceive(asyncState.Buffer0asyncState.Buffer.LengthSocketFlags.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.Buffer0asyncState.Buffer.LengthSocketFlags.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.SocketMF);
        
obj.Connector client;
        if (
MF.client == null)
        {
            
MF.client client;
        }
        
Network.Packets.ComputerInformation ComputerInformation = new Network.Packets.ComputerInformation(trueclient);
        
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[] packetAsyncSocketWrapper obj)
    {
        try
        {
            
Client.State client = (Client.State)obj.Connector;
            
Network.PacketHandler.Handle(packetclient);

        }
        catch (
Exception e)
        {
            
Program.WriteLine(e.ToString());
        }
    }

}

public static 
void Handle(byte[] packetClient.State client)
    {
        if (
packet == null)
            return;
        if (
client == null)
            return;

        
ushort ID BitConverter.ToUInt16(packet0);
        
ushort Length BitConverter.ToUInt16(packet2);

        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(messageclient);
                    break;
                }
            case 
1005:
                {
                    
Network.Packets.StartSession StartSession = new Network.Packets.StartSession();
                    
StartSession.Deserialize(packet);
                    
client.Session = new Data.Session(clientStartSession);
                    
client.Session.Start();
                    break;
                }
            case 
1007:
                {
                    
Network.Packets.EditSession EditSession = new Network.Packets.EditSession();
                    
EditSession.Deserialize(packet);
                    
client.Session.Edit(EditSession.AddEditSession.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 senderDoWorkEventArgs e)
        {
            
Program.StartEngine();
        }
        
#region Form Load / Close
        
private void MainForm_FormClosing(object senderFormClosingEventArgs e)
        {

        }

        private 
void MainForm_Load(object senderEventArgs 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(thisclient);
                        
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(thisclient);
                                    
HandForm.UserForm.AdminControlIsVisible false;
                                    
HandForm.UserForm.UpdateStart();
                                    
HandForm.ShowDialog(this);
                                    break;
                                }
                            case 
false:
                                {
                                    
this.Hide();
                                    
HandForm = new HandForm(thisclient);
                                    
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 mainFormClient.State client)
        {
            
InitializeComponent();
            
this.MainForm mainForm;
            
this.client client;
            
UserForm = new UserForm(mainFormclient);
            
slider = new SlidingController(UserFormthis);
        }

        private 
void HandForm_Load(object senderEventArgs e)
        {
            
UserForm.Show();
            
slider.Initialize();
        }

        private 
void HandForm_MouseClick(object senderMouseEventArgs 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 senderFormClosingEventArgs e)
        {
            
UserForm.Close();
        }
    } 
PHP Code:
public partial class UserForm Form
    
{
        private 
Client.State client;
        private 
MainForm MF;
        public 
UserForm(MainForm mainFormClient.State client)
        {
            
this.MF mainForm;
            
this.client client;
            
InitializeComponent();
        }

        public 
bool AdminControlIsVisible
        
{
            
set this.Exit_Key.Enabled valuethis.Options_Key.Enabled value; }
        }

        
        private 
void Options_Key_Click(object senderEventArgs e)
        {
            
client.Session.Pause();
        }

        private 
void Exit_Key_Click(object senderEventArgs e)
        {

        }

        private 
void Logout_Key_Click(object senderEventArgs e)
        {
            if (
MessageBox.Show("Are you sure that you want to end the session ?""HotCafe"MessageBoxButtons.YesNoMessageBoxIcon.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 Xio.#25
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 ...
[Only registered and activated users can see links. Click Here To Register...]

Also: Nice job at copying the Codeproject signature into yours lol.
10/24/2014 12:12 donn#26
Am I wrong or showing a modal dialog freezes the thread that calls it till the dialog is closed?
10/24/2014 16:48 KraHen#27
Quote:
Originally Posted by donn View Post
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 abdeen#28
Quote:
Originally Posted by KraHen View Post
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.SocketMF);
        
obj.Connector client;
        if (
MF.client == null)
        {
            
MF.client client;
        }
        
Network.Packets.ComputerInformation ComputerInformation = new Network.Packets.ComputerInformation(trueclient);
        
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[] packetAsyncSocketWrapper obj)
    {
        try
        {
            
Client.State client = (Client.State)obj.Connector;
            
Network.PacketHandler.Handle(packetclient);

        }
        catch (
Exception e)
        {
            
Program.WriteLine(e.ToString());
        }
    }


PacketHandler.cs

PHP Code:
public static class PacketHandler
{
    public static 
void Handle(byte[] packetClient.State client)
    {
        if (
packet == null)
            return;
        if (
client == null)
            return;

        
ushort ID BitConverter.ToUInt16(packet0);
        
ushort Length BitConverter.ToUInt16(packet2);

        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(messageclient);
                    break;
                }
            case 
1005:
                {
                    
Network.Packets.StartSession StartSession = new Network.Packets.StartSession();
                    
StartSession.Deserialize(packet);
                    
client.Session = new Data.Session(clientStartSession);
                    
client.Session.Start();
                    break;
                }
            case 
1007:
                {
                    
Network.Packets.EditSession EditSession = new Network.Packets.EditSession();
                    
EditSession.Deserialize(packet);
                    
client.Session.Edit(EditSession.AddEditSession.Time);
                    break;
                }
            default:
                {
                    
client.Send(packet);
                    break;
                }
        }
    }

    private static 
void Chat(Message messageClient.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 psych0zius#29
abdeen shut the fuck up, nobody cares about your problems
10/24/2014 20:23 Best Coder 2014#30
Quote:
Originally Posted by abdeen View Post
PHP Code:
if (AuthServer.Connect("192.168.1.100"9958))
{
     
GC.Collect();

[Only registered and activated users can see links. Click Here To Register...]

Please, abdeen, stop yourself.