Click here to Skip to main content
15,895,799 members
Home / Discussions / C#
   

C#

 
AnswerRe: Create database Pin
Manas Bhardwaj26-Jun-09 22:21
professionalManas Bhardwaj26-Jun-09 22:21 
AnswerRe: Create database Pin
onlyx27-Jun-09 5:00
onlyx27-Jun-09 5:00 
AnswerRe: Create database Pin
Ravi Bhavnani27-Jun-09 6:46
professionalRavi Bhavnani27-Jun-09 6:46 
Questionprint Pin
Sudhirg kumar26-Jun-09 21:27
Sudhirg kumar26-Jun-09 21:27 
AnswerREPOST Pin
dan!sh 26-Jun-09 21:33
professional dan!sh 26-Jun-09 21:33 
AnswerRe: print Pin
Enver Maroshi26-Jun-09 21:33
Enver Maroshi26-Jun-09 21:33 
AnswerRe: print Pin
Christian Graus26-Jun-09 22:03
protectorChristian Graus26-Jun-09 22:03 
Questionproducer / cosumer Pin
nona_toti26-Jun-09 21:23
nona_toti26-Jun-09 21:23 
Hi guys ....
I've been writ a simple program using sockets to send data from client to server
here is my program
server code
<pre>
public class SocketListener
{
      public static string data = null;

      public static void StartListening()
      {
            byte[] bytes = new Byte[1024];

            IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
            IPAddress ipAddress = ipHostInfo.AddressList[0];
            IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 11000);

            Socket listener = new Socket(AddressFamily.InterNetwork,
                  SocketType.Stream, ProtocolType.Tcp);

            try
            {
                  listener.Bind(localEndPoint);
                  listener.Listen(10);
                  while (true)
                  {
                        Console.WriteLine("Waiting for a connection...");
                        Socket handler = listener.Accept();
                        data = null;
                        while (true)
                        {
                              bytes = new byte[1024];
                              int bytesRec = handler.Receive(bytes);
                              data += Encoding.ASCII.GetString(bytes, 0, bytesRec);
                              if (data.IndexOf("&lt; My 1st socket prog &gt;") &gt; -1)
                              {
                                    break;
                              }
                        }


                        Console.WriteLine("Text received : {0}", data);
                        byte[] msg = Encoding.ASCII.GetBytes(data);

                        handler.Send(msg);
                        handler.Shutdown(SocketShutdown.Both);
                        handler.Close();
                  }

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

            Console.WriteLine("\nPress ENTER to continue...");
            Console.Read();

      }

      public static int Main(String[] args)
      {
            StartListening();
            return 0;
      }
}
</pre>

and client code
<pre>using System;
public class SocketClient
{

      public static void StartClient() {
            byte[] bytes = new byte[1024];
            try {

                  IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName());
                  IPAddress ipAddress = ipHostInfo.AddressList[0];
                  IPEndPoint remoteEP = new IPEndPoint(ipAddress,11000);

                  Socket sender = new Socket(AddressFamily.InterNetwork,
                        SocketType.Stream, ProtocolType.Tcp );

                  try {
                        sender.Connect(remoteEP);

                        Console.WriteLine("Socket connected to {0}",
                              sender.RemoteEndPoint.ToString());
                        byte[] msg = Encoding.ASCII.GetBytes("This is a test&lt; My 1st socket prog &gt;");

                        int bytesSent = sender.Send(msg);

                        int bytesRec = sender.Receive(bytes);
                        Console.WriteLine("Echoed test = {0}",
                              Encoding.ASCII.GetString(bytes,0,bytesRec));

                        sender.Shutdown(SocketShutdown.Both);
                        sender.Close();
                       
                  } catch (ArgumentNullException ane) {
                        Console.WriteLine("ArgumentNullException : {0}",ane.ToString());
                  } catch (SocketException se) {
                        Console.WriteLine("SocketException : {0}",se.ToString());
                  } catch (Exception e) {
                        Console.WriteLine("Unexpected exception : {0}", e.ToString());
                  }

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

      public static int Main(String[] args)
      {
            StartClient();
            return 0;
      }
}</pre>
now I want to let 1st client "producer" generates random message and sends it to the server, then server checks the buffer, if there is enough space to store it, then it stores it, otherwise it neglects the message

and 2nd client "consumer" will be connected to the server and asks the server for data, the server in turn will check the buffer. If the buffer is empty then the consumer will wait
that's all and thank u
QuestionHow to move values from one listbox to another listbox?can anyone help me? Pin
swetha_insoft26-Jun-09 21:20
swetha_insoft26-Jun-09 21:20 
AnswerRe: How to move values from one listbox to another listbox?can anyone help me? Pin
Christian Graus26-Jun-09 21:24
protectorChristian Graus26-Jun-09 21:24 
GeneralRe: How to move values from one listbox to another listbox?can anyone help me? Pin
swetha_insoft26-Jun-09 21:32
swetha_insoft26-Jun-09 21:32 
GeneralRe: How to move values from one listbox to another listbox?can anyone help me? Pin
Christian Graus26-Jun-09 23:41
protectorChristian Graus26-Jun-09 23:41 
JokeRe: How to move values from one listbox to another listbox?can anyone help me? Pin
Uwe Keim27-Jun-09 10:24
sitebuilderUwe Keim27-Jun-09 10:24 
AnswerRe: How to move values from one listbox to another listbox?can anyone help me? Pin
dan!sh 26-Jun-09 21:30
professional dan!sh 26-Jun-09 21:30 
GeneralRe: How to move values from one listbox to another listbox?can anyone help me? Pin
swetha_insoft26-Jun-09 21:37
swetha_insoft26-Jun-09 21:37 
GeneralRe: How to move values from one listbox to another listbox?can anyone help me? Pin
dan!sh 26-Jun-09 21:55
professional dan!sh 26-Jun-09 21:55 
GeneralRe: How to move values from one listbox to another listbox?can anyone help me? Pin
swetha_insoft26-Jun-09 22:18
swetha_insoft26-Jun-09 22:18 
GeneralRe: How to move values from one listbox to another listbox?can anyone help me? Pin
dan!sh 26-Jun-09 22:22
professional dan!sh 26-Jun-09 22:22 
GeneralRe: How to move values from one listbox to another listbox?can anyone help me? Pin
swetha_insoft27-Jun-09 0:23
swetha_insoft27-Jun-09 0:23 
GeneralRe: How to move values from one listbox to another listbox?can anyone help me? Pin
padmanabhan N27-Jun-09 1:03
padmanabhan N27-Jun-09 1:03 
GeneralRe: How to move values from one listbox to another listbox?can anyone help me? Pin
swetha_insoft27-Jun-09 1:09
swetha_insoft27-Jun-09 1:09 
AnswerRe: How to move values from one listbox to another listbox?can anyone help me? Pin
padmanabhan N26-Jun-09 23:09
padmanabhan N26-Jun-09 23:09 
Questionerror ---Cannot find table 0. Pin
KIDYA26-Jun-09 20:33
KIDYA26-Jun-09 20:33 
AnswerRe: error ---Cannot find table 0. Pin
dan!sh 26-Jun-09 20:51
professional dan!sh 26-Jun-09 20:51 
GeneralRe: error ---Cannot find table 0. Pin
KIDYA26-Jun-09 21:07
KIDYA26-Jun-09 21:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.