Send a suggestion!

We're building a brand new version of the site, and we'd love to hear your ideas

Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

[3918] Socket Programming in C# - Part 1

Last post 04-05-2008 11:30 PM by maxdev. 17 replies.
Page 1 of 2 (18 items) 1 2 Next >
Sort Posts: Previous Next
  • 01-01-1999 12:00 AM

    [3918] Socket Programming in C# - Part 1

    This thread is for discussions of Socket Programming in C# - Part 1.

    • Post Points: 65
  • Advertisement

    • Red Gate Software

    Advertisement

    Want to boost your .NET application performance?

    Some developers always seem to write efficient and lightening-fast code. What is their secret? It’s ANTS Profiler. “We improved the performance of the application up to 10 times” Dan Ports, Intrigma.

    Try it for yourself now.

  • 08-25-2003 11:02 AM In reply to

    • garatej
    • Not Ranked
    • Joined on 08-22-2003
    • Junior Member
    • Points 75

    Server/Client in the same computer

    I only speak a lite bit of english.

    I would like to know how to run the server and the client in the
    same computer to text my application before to start with two
    diferents computers.

    Thank Javier
    • Post Points: 0
  • 09-30-2003 10:41 AM In reply to

    • hamzahwh
    • Not Ranked
    • Joined on 09-29-2003
    • New Member
    • Points 20
    hello my name hamza , my email hamzahwh@yahoo.com

    you can do client / server in the same computer by useing concept "localhost" if you send to my your program i will correct to you and send to you .

    and also i try to do multi client / server in c# programming if you can help my after .
    • Post Points: 0
  • 10-30-2003 5:39 AM In reply to

    long 23 seconds timeout

    When the Client tries to connect to a disconnected IP address, there is a long timeout of 23 seconds...
    How can we reduce this timeout?
    What is the method to control it?

    Thanks for help
    • Post Points: 0
  • 11-13-2003 6:58 AM In reply to

    Sockets Synchronous Vs Async

    Regarding blocking socket calls. Are u assuming .net does the polling. As no additional code has to be written for polling. So no need to return to main thread and a delegate also is not required.  

    Now consider in asynchronous mode, multiple clients are connected. Then the delegates for beginreceive will fire at will and when multiple fire at same time, it gets stacked as there only one thread. Then the last delegate to be fired will be processed and then down the stack. In fact if we need to sequence something, a lot of coding is involved. The flow also is not clear and criss crosses.

    Could you comment on the above. I have a req which needs sequential access of the messages and depends on a flow mapping of messages when there are multiple clients.  I been thinking async(with delegates) will be an overhead and confusing/complicated to implement.
    • Post Points: 0
  • 03-07-2005 12:37 PM In reply to

    • request
    • Not Ranked
    • Joined on 03-07-2005
    • New Member
    • Points 15

    setting header information while requesting thru s

    Hi
    I am trying server request/response program using socket class. here i couldn't send headers with the request to the proxy server.when i send the request i should able to get the response from the server.
    if u have any idea please help me out.
    Regards
    request.
    --------------------------------
    • Post Points: 0
  • 04-06-2005 2:54 AM In reply to

    • suraheel
    • Not Ranked
    • Joined on 04-06-2005
    • New Member
    • Points 5

    client to client programming

    assalam-o-aleykum, im raheel from pakistan, and i want to know about client to client messanger, plz guide me. thanks. my mail raheel_s81@hotmail.com
    • Post Points: 0
  • 07-16-2005 12:40 PM In reply to

    • blumka
    • Not Ranked
    • Joined on 07-16-2005
    • New Member
    • Points 15

    Help

    When the Client tries to connect to a disconnected IP address, there is a long timeout of 23 seconds...
    How can we reduce this timeout?
    What is the method to control it?

    Thanks
    • Post Points: 0
  • 10-17-2005 1:41 PM In reply to

    help...please

    there is aproblem meet me ,i designed aprogram simulate the work of credit card by designing two programs one used by auser and the other one for the administration and deal with database ,but when i put  the two program on different computer they are not work


    the tcplistner statement as follow:
                    listener = new TcpListener(1500);

    the tcpclient statement as follow:
    client = new TcpClient("192.168.1.1", 1500);
     

    since the "192.168.1.1" is the ip address of the machine that the server program run at
    • Post Points: 0
  • 01-19-2006 6:00 PM In reply to

    • spowens
    • Not Ranked
    • Joined on 01-19-2006
    • New Member
    • Points 15

    Porting sample code to 2005

    I am using Visual C# 2005. It turns out that there are some cross thread calls to forms controls which are flagged as unsafe when running under C# 2005.  I will post fixes to these a little later.  
    • Post Points: 0
  • 01-19-2006 6:22 PM In reply to

    • spowens
    • Not Ranked
    • Joined on 01-19-2006
    • New Member
    • Points 15

    The fix is in.

    Ok, here is the fix to make the samples work under C# 2005 without exceptions.

    In the SocketServer project modify the SocketServer class as follows:

    1.  Add the following delegate declaration:

           // This delegate enables asynchronous calls for setting
           // the text property on a TextBox control.
           delegate void AppendTextCallback(string text);

    2.  Add the following method:

           // If the calling thread is different from the thread that
           // created the TextBox control, this method creates a
           // AppendTextCallback and calls itself asynchronously using the
           // Invoke method.
           //
           // If the calling thread is the same as the thread that created
           // the TextBox control, the Text property is set directly.
           private void AppendRxText(string text)
           {
               // InvokeRequired required compares the thread ID of the
               // calling thread to the thread ID of the creating thread.
               // If these threads are different, it returns true.
               
               if (this.txtDataRx.InvokeRequired)
               {
                   AppendTextCallback d = new AppendTextCallback(AppendRxText);
                   this.Invoke(d, new object[] { text });
               }
               else
               {
                   txtDataRx.Text = txtDataRx.Text + text;
               }
           }

    3. Replace the OnDataReceived method with the following, or make the minor one line code change
    as commented in the method below if you prefer:
             public  void OnDataReceived(IAsyncResult asyn)
             {
       try
       {
             CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState ;
             //end receive...
             int iRx  = 0 ;
             iRx = theSockId.thisSocket.EndReceive (asyn);
             char[] chars = new char[iRx +  1];
             System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
             int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);
             System.String szData = new System.String(chars);
                         // Old offending line
             //txtDataRx.Text = txtDataRx.Text + szData;
                         AppendRxText(szData);
             WaitForData(m_socWorker );
       }
       catch (ObjectDisposedException )
       {
            System.Diagnostics.Debugger.Log(0,"1","\nOnDataReceived: Socket has been closed\n");
       }
       catch(SocketException se)
       {
             MessageBox.Show (se.Message );
       }
              }
    • Post Points: 15
  • 02-25-2007 10:19 PM In reply to

    • Hunaim
    • Not Ranked
    • Joined on 02-25-2007
    • New Member
    • Points 5

    Help required regarding Instant Messenger in .Net

    Hello spowens,

    Sir i am new to .Net and i want to create chatting software which can communicate over the internet too.
    I have searched a lot but the help which i found couldn't solve my problem. Please sir
    i have to complete my semester project of Bs(Computer Engineering) i need help.
    you can mail me the solution on my email dr_hunaindurrani@yahoo.com i will be great full to you.

    Thanks in advance
    Hunain Durrani.









    • Post Points: 5
  • 03-15-2007 4:41 PM In reply to

    • girishrk
    • Not Ranked
    • Joined on 03-15-2007
    • New Member
    • Points 5

    Re: [3918] Socket Programming in C# - Part 1

    I'm having Interoperability problems with a Java client. The Java Client connects to a TCP server application, and immediately sends some data, and closes the connection.
    After the client is connected, the server recieves only 1 byte of data.
    If I introduce a delay(Thread.Sleep, MBox, or a breakpoint),  between the OnClientConnect, WaitForData and OnDataReceived functions, I get complete data.
    This shouldn't happen logically. I'm wondering what might be the problem.






    • Post Points: 5
  • 04-10-2007 1:26 PM In reply to

    • eswars
    • Not Ranked
    • Joined on 04-10-2007
    • India
    • New Member
    • Points 5

    Re: [3918] Socket Programming in C# - Part 1

    Hi,

     I want an application , where a single client using more than one server (Same Application running in more than one machines.).Client listening  to a single port for all the servers it connected to.
       Client application will receive huge data frequently. Server will process and send the data to client.
      As i want the application to be started first i made the main application as Server. Am i right.
     or Do we have option for passive Servers.

    With Thanks,
    Eswar

     

















    • Post Points: 5
  • 05-03-2007 1:30 PM In reply to

    • Dandel
    • Not Ranked
    • Joined on 05-02-2007
    • United States
    • New Member
    • Points 15

    Re: [3918] Socket Programming in C# - Part 1

    all i haft to say is that this is a very informative tutorial and i'd recommend it to anyone who wants to try building socket based software in C#.

    • Post Points: 15
Page 1 of 2 (18 items) 1 2 Next >