Register for your free account! | Forgot your password?

You last visited: Today at 06:03

  • Please register to post and access all features, it's quick, easy and FREE!

Advertisement



Chat server/cleint

Discussion on Chat server/cleint within the CO2 Private Server forum part of the Conquer Online 2 category.

Reply
 
Old   #1
 
elite*gold: 80
Join Date: Sep 2007
Posts: 642
Received Thanks: 168
Chat server/cleint

Ok can anyone help me with creating a Chat Server and Chat Client. And please dont close this because im trying to make one so that i can put the client in the CO folder so people can talk to one another. Now if your just gonna say "Google it" or "Search" do not post, or i will report you. I have tried google. And none of them make sense to me, or even work. Any help would be appreciated
Santa is offline  
Old 07/29/2009, 15:08   #2
 
xellios's Avatar
 
elite*gold: 0
Join Date: Aug 2007
Posts: 310
Received Thanks: 13
[Chat client]
Code:
/*
CREDITS TO SIDZONE
*/
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class TcpClientSample
{
  
    public static void Main()
   {
      byte[] data = new byte[1024];
      string input;
      int port;
      TcpClient server;
      
      System.Console.WriteLine ("Please Enter the port number of Server:\n");
      port = Int32.Parse( System.Console.ReadLine());
      try
      {
         server = new TcpClient("127.0.0.1",port);
      } catch (SocketException)
      {
         Console.WriteLine("Unable to connect to server");
         return;
      }
      Console.WriteLine("Connected to the Server...");
      Console.WriteLine("Enter the message to send it to the Sever");
        NetworkStream ns = server.GetStream();

      StateObject state = new StateObject();
      state.workSocket = server.Client;
      server.Client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                  new AsyncCallback((new TcpClientSample()).OnReceive), state);

      while(true)
      {
         input = Console.ReadLine();
         if (input == "exit")
            break;
         ns.Write(Encoding.ASCII.GetBytes(input), 0, input.Length);
         ns.Flush();

         //data = new byte[1024];
         //recv = ns.Read(data, 0, data.Length);
         //stringData = Encoding.ASCII.GetString(data, 0, recv);
         //Console.WriteLine(stringData);
      }
      Console.WriteLine("Disconnecting from server...");
      ns.Close();
      server.Close();
   }


    public void OnReceive(IAsyncResult ar)
    {
        String content = String.Empty;

        // Retrieve the state object and the handler socket
        // from the asynchronous state object.
        StateObject state = (StateObject)ar.AsyncState;
        Socket handler = state.workSocket;
        int bytesRead;

        if (handler.Connected) // Credits to cidzone
        {

            // Read data from the client socket. 
            try
            {
                bytesRead = handler.EndReceive(ar);
                if (bytesRead > 0)
                {
                    // There  might be more data, so store the data received so far.
                    state.sb.Remove(0, state.sb.Length);
                    state.sb.Append(Encoding.ASCII.GetString(
                                     state.buffer, 0, bytesRead));

                    // Display Text in Rich Text Box
                    content = state.sb.ToString();
                    Console.WriteLine(content);

                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                        new AsyncCallback(OnReceive), state);

                }
            }

            catch (SocketException socketException)
            {
                //WSAECONNRESET, the other side closed impolitely
                if (socketException.ErrorCode == 10054 || ((socketException.ErrorCode != 10004) && (socketException.ErrorCode != 10053)))
                {
                    handler.Close();
                }
            }

        // Eat up exception....Meh
            catch (Exception exception)
            {
                //MessageBox.Show(exception.Message + "\n" + exception.StackTrace);

            }
        }
    }


}

public class StateObject
{
    // Client  socket.
    public Socket workSocket = null;
    // Size of receive buffer.
    public const int BufferSize = 1024;
    // Receive buffer.
    public byte[] buffer = new byte[BufferSize];
    // Received data string.
    public StringBuilder sb = new StringBuilder();
}


-----------------------------------
Chat Server



-----------------------------------

Add credits in your use.
+Thanks if u like it



#Request to close threadstarter got his request^^
xellios is offline  
Old 07/29/2009, 16:39   #3
 
_Emme_'s Avatar
 
elite*gold: 1142
Join Date: Aug 2006
Posts: 2,464
Received Thanks: 1,162
Quote:
Originally Posted by xellios View Post
[Chat client]

-----------------------------------
Chat Server



-----------------------------------

Add credits in your use.
+Thanks if u like it



#Request to close threadstarter got his request^^
Yeah, give credits to Sidzone..
xellios, don't take other codes and claim them as your own.

_Emme_ is offline  
Old 07/29/2009, 16:44   #4
 
elite*gold: 0
Join Date: Jul 2009
Posts: 548
Received Thanks: 52
or you can use this too
f0am is offline  
Old 07/29/2009, 21:54   #5
 
elite*gold: 80
Join Date: Sep 2007
Posts: 642
Received Thanks: 168
Quote:
Originally Posted by xellios View Post
[Chat client]
Code:
/*
CREDITS TO SIDZONE
*/
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class TcpClientSample
{
  
    public static void Main()
   {
      byte[] data = new byte[1024];
      string input;
      int port;
      TcpClient server;
      
      System.Console.WriteLine ("Please Enter the port number of Server:\n");
      port = Int32.Parse( System.Console.ReadLine());
      try
      {
         server = new TcpClient("127.0.0.1",port);
      } catch (SocketException)
      {
         Console.WriteLine("Unable to connect to server");
         return;
      }
      Console.WriteLine("Connected to the Server...");
      Console.WriteLine("Enter the message to send it to the Sever");
        NetworkStream ns = server.GetStream();

      StateObject state = new StateObject();
      state.workSocket = server.Client;
      server.Client.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                  new AsyncCallback((new TcpClientSample()).OnReceive), state);

      while(true)
      {
         input = Console.ReadLine();
         if (input == "exit")
            break;
         ns.Write(Encoding.ASCII.GetBytes(input), 0, input.Length);
         ns.Flush();

         //data = new byte[1024];
         //recv = ns.Read(data, 0, data.Length);
         //stringData = Encoding.ASCII.GetString(data, 0, recv);
         //Console.WriteLine(stringData);
      }
      Console.WriteLine("Disconnecting from server...");
      ns.Close();
      server.Close();
   }


    public void OnReceive(IAsyncResult ar)
    {
        String content = String.Empty;

        // Retrieve the state object and the handler socket
        // from the asynchronous state object.
        StateObject state = (StateObject)ar.AsyncState;
        Socket handler = state.workSocket;
        int bytesRead;

        if (handler.Connected) // Credits to cidzone
        {

            // Read data from the client socket. 
            try
            {
                bytesRead = handler.EndReceive(ar);
                if (bytesRead > 0)
                {
                    // There  might be more data, so store the data received so far.
                    state.sb.Remove(0, state.sb.Length);
                    state.sb.Append(Encoding.ASCII.GetString(
                                     state.buffer, 0, bytesRead));

                    // Display Text in Rich Text Box
                    content = state.sb.ToString();
                    Console.WriteLine(content);

                    handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0,
                        new AsyncCallback(OnReceive), state);

                }
            }

            catch (SocketException socketException)
            {
                //WSAECONNRESET, the other side closed impolitely
                if (socketException.ErrorCode == 10054 || ((socketException.ErrorCode != 10004) && (socketException.ErrorCode != 10053)))
                {
                    handler.Close();
                }
            }

        // Eat up exception....Meh
            catch (Exception exception)
            {
                //MessageBox.Show(exception.Message + "\n" + exception.StackTrace);

            }
        }
    }


}

public class StateObject
{
    // Client  socket.
    public Socket workSocket = null;
    // Size of receive buffer.
    public const int BufferSize = 1024;
    // Receive buffer.
    public byte[] buffer = new byte[BufferSize];
    // Received data string.
    public StringBuilder sb = new StringBuilder();
}


-----------------------------------
Chat Server



-----------------------------------

Add credits in your use.
+Thanks if u like it



#Request to close threadstarter got his request^^
Thanks, hope it works, notice there is no form in there? Any idea on how to add one to work?

Quote:
Originally Posted by _StarScream_ View Post
Google it, or search it -.-

:P
xD, couldn't help but laugh cause the little face

Quote:
Originally Posted by xellios View Post
Why do you even respond to it i gave him a answer there is no need being "funny" ffs?
I found it funny....

Quote:
Originally Posted by EmmeTheCoder View Post
Yeah, give credits to Sidzone..
xellios, don't take other codes and claim them as your own.

I knew the credits were to sidzone, as its in the code...

Quote:
Originally Posted by f0am View Post
or you can use this too
Aha, hope i can get it to work xD
Santa is offline  
Old 07/30/2009, 05:07   #6
 
elite*gold: 20
Join Date: Apr 2008
Posts: 2,281
Received Thanks: 913
#Cleaned

Anymore arguing and flaming will result in infractions for all of you.
kinshi88 is offline  
Old 07/30/2009, 05:09   #7
 
elite*gold: 80
Join Date: Sep 2007
Posts: 642
Received Thanks: 168
Quote:
Originally Posted by kinshi88 View Post
#Cleaned

Anymore arguing and flaming will result in infractions for all of you.
Emme too?
Santa is offline  
Reply


Similar Threads Similar Threads
Exo Metin2 P-server cleint/exe
07/30/2010 - Metin2 Private Server - 7 Replies
Huhu ich spiele seit heute aufm p-server Exo Metin2. aber da sehen die fertigkeiten voll krank aus und ich wollte fragen ob einer vlt ne exe oder nen clienten hat damit des normal aussieht
P-Server CHAT und GM CHAT /b /n Problem HILFE
11/07/2009 - Metin2 Private Server - 5 Replies
Hallo leute, Also, seit dem ich Updates auf meinem PC insterlliert habe und den PC neugestartet habe, hat mein Server irgendein Problem bekommen. Wenn ich mich einlogge kann ich noch Items erstellen kämpfen usw.. außer in irgendeiner Form Chatten. So zB. wenn ich versuche was zu schreiben kommt der Satz halt nicht über dem Kopf oder im Chat und dann ist alles weg also kann keine Items erstellen und nur Attacken einsetzten MObs kann ich nicht töten, also so als ob das Internet dann weg wäre....
NO-DC CLEINT PLS:)
04/06/2009 - SRO Private Server - 1 Replies
guys where i can get a no-dc client for p server??



All times are GMT +1. The time now is 06:03.


Powered by vBulletin®
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
SEO by vBSEO ©2011, Crawlability, Inc.
This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Support | Contact Us | FAQ | Advertising | Privacy Policy | Terms of Service | Abuse
Copyright ©2025 elitepvpers All Rights Reserved.