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

C#

 
GeneralRe: My project is not reflecting current changes Pin
Pete O'Hanlon11-Feb-08 10:06
mvePete O'Hanlon11-Feb-08 10:06 
GeneralRe: My project is not reflecting current changes Pin
Luc Pattyn11-Feb-08 10:38
sitebuilderLuc Pattyn11-Feb-08 10:38 
QuestionUDP Send function sends duplicate data Pin
Chase Davis11-Feb-08 9:34
Chase Davis11-Feb-08 9:34 
GeneralRe: UDP Send function sends duplicate data Pin
led mike11-Feb-08 10:01
led mike11-Feb-08 10:01 
GeneralRe: UDP Send function sends duplicate data Pin
Chase Davis11-Feb-08 11:09
Chase Davis11-Feb-08 11:09 
GeneralRe: UDP Send function sends duplicate data Pin
led mike11-Feb-08 11:16
led mike11-Feb-08 11:16 
GeneralRe: UDP Send function sends duplicate data Pin
Chase Davis11-Feb-08 12:30
Chase Davis11-Feb-08 12:30 
GeneralRe: UDP Send function sends duplicate data Pin
led mike12-Feb-08 9:30
led mike12-Feb-08 9:30 
Chase, like I said I have had no experience with UDP so I just put together two apps, Sender and Client, they work as expected here is the code

Sender Application
public partial class Form1 : Form
{
    private System.Net.Sockets.Socket _sock;
    private System.Net.IPEndPoint _ipEnd;

    public Form1()
    {
        InitializeComponent();

        _sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

        IPHostEntry hostent = Dns.Resolve(Dns.GetHostName());
        _ipEnd = new IPEndPoint(hostent.AddressList[0], 3030);
    }

    private void button1_Click(object sender, EventArgs e)
    {
        byte[] bytes = Encoding.ASCII.GetBytes(textBox1.Text);
        Cursor oldCursor = Cursor;
        Cursor = System.Windows.Forms.Cursors.WaitCursor;
        _sock.SendTo(bytes, _ipEnd);
        Cursor = oldCursor;

    }
}


Client application

public partial class Form1 : Form
{
    UdpClient _client;
    IPEndPoint _ipEndPoint;

    public Form1()
    {
        InitializeComponent();

        _ipEndPoint = new IPEndPoint(IPAddress.Any, 3030);
        _client = new UdpClient(_ipEndPoint);

        _client.BeginReceive(Recv, new State(_client, _ipEndPoint, this));
    }

    public void OnRecvMsg(string msg)
    {
        if( textBox1.Text.Length > 0)
            textBox1.Text = String.Format("{0}\r\n{1}", textBox1.Text, msg);
        else
            textBox1.Text = msg;
    }

    public static void Recv(IAsyncResult ar)
    {
        State state = ar.AsyncState as State;
        Byte[] bytes = state.Client.EndReceive(ar, ref state.EndPoint);
        state.TForm.OnRecvMsg(Encoding.ASCII.GetString(bytes));
        state.Client.BeginReceive(Recv, state);
    }

}

internal class State
{
    public IPEndPoint EndPoint;
    public UdpClient Client;
    public Form1 TForm;

    internal State(UdpClient client, IPEndPoint endpoint, Form1 form)
    {
        EndPoint = endpoint;
        Client = client;
        TForm = form;
    }
}



led mike

Generalan application for showing shared files using c# and .net Pin
addemy11-Feb-08 7:24
addemy11-Feb-08 7:24 
GeneralRe: an application for showing shared files using c# and .net Pin
led mike11-Feb-08 7:51
led mike11-Feb-08 7:51 
GeneralRe: an application for showing shared files using c# and .net Pin
addemy11-Feb-08 7:59
addemy11-Feb-08 7:59 
GeneralRe: an application for showing shared files using c# and .net [modified] Pin
led mike11-Feb-08 8:13
led mike11-Feb-08 8:13 
Generalsystem.drawing.color [modified] Pin
s3rro11-Feb-08 7:11
s3rro11-Feb-08 7:11 
GeneralRe: system.drawing.color Pin
led mike11-Feb-08 8:07
led mike11-Feb-08 8:07 
GeneralRe: system.drawing.color Pin
Insincere Dave11-Feb-08 8:34
Insincere Dave11-Feb-08 8:34 
GeneralRe: system.drawing.color Pin
led mike11-Feb-08 8:38
led mike11-Feb-08 8:38 
GeneralRe: system.drawing.color Pin
s3rro11-Feb-08 8:53
s3rro11-Feb-08 8:53 
GeneralRe: system.drawing.color Pin
Pete O'Hanlon11-Feb-08 10:16
mvePete O'Hanlon11-Feb-08 10:16 
QuestionRequest is not available in this context Pin
Ryno Burger11-Feb-08 6:18
Ryno Burger11-Feb-08 6:18 
GeneralRe: Request is not available in this context Pin
led mike11-Feb-08 6:22
led mike11-Feb-08 6:22 
GeneralRe: Request is not available in this context Pin
Ryno Burger11-Feb-08 6:27
Ryno Burger11-Feb-08 6:27 
GeneralRe: Request is not available in this context Pin
led mike11-Feb-08 6:47
led mike11-Feb-08 6:47 
GeneralRe: Request is not available in this context Pin
Not Active11-Feb-08 6:24
mentorNot Active11-Feb-08 6:24 
GeneralRe: Request is not available in this context Pin
Steve Westbrook11-Feb-08 6:38
Steve Westbrook11-Feb-08 6:38 
GeneralRe: Request is not available in this context Pin
leppie11-Feb-08 8:03
leppie11-Feb-08 8:03 

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.