Click here to Skip to main content
16,004,901 members
Home / Discussions / C#
   

C#

 
AnswerRe: Problems with StreamWriter Class Pin
martin_hughes3-Aug-07 4:49
martin_hughes3-Aug-07 4:49 
GeneralRe: Problems with StreamWriter Class Pin
mouthbag3-Aug-07 4:55
mouthbag3-Aug-07 4:55 
AnswerRe: Problems with StreamWriter Class Pin
Guffa3-Aug-07 5:40
Guffa3-Aug-07 5:40 
GeneralRe: Problems with StreamWriter Class Pin
Luc Pattyn3-Aug-07 5:52
sitebuilderLuc Pattyn3-Aug-07 5:52 
QuestionHow can I use a parsed UDP byte stream to continually update a GUI form ? Pin
flyingnome3-Aug-07 4:07
flyingnome3-Aug-07 4:07 
AnswerRe: How can I use a parsed UDP byte stream to continually update a GUI form ? Pin
martin_hughes3-Aug-07 5:17
martin_hughes3-Aug-07 5:17 
GeneralRe: How can I use a parsed UDP byte stream to continually update a GUI form ? Pin
flyingnome3-Aug-07 5:36
flyingnome3-Aug-07 5:36 
GeneralRe: How can I use a parsed UDP byte stream to continually update a GUI form ? Pin
martin_hughes3-Aug-07 5:49
martin_hughes3-Aug-07 5:49 
I'm not sure this will be any use to you, but here is a simple listening application I knocked up. When running it'll listen for TFTP requests on Port 69, and you should be able to see received data written to the console and that the console remains able to accept user input:

class Program
  {
      public static bool listen = true;
      public static IPEndPoint endPoint;
      public static UdpClient udpClient;

      static void Main(string[] args)
      {
          //Example of crummy server app running
          //Starts the listener, and writes the received data to the console
          //while allowing the user to interact with program - "q" quits.
          Console.WriteLine("Server Running...");


          endPoint = new IPEndPoint(IPAddress.Any, 69);
          udpClient = new UdpClient(endPoint);

          ReceiveMessages();
          while (listen)
          {
              string str = Console.ReadLine();
              if (str == "q")
              {
                  listen = false;
              }
              else
              {
                  Console.WriteLine(str);
              }
          }
      }

      //This is the callback, used to process the received data
      public static void ReceiveCallback(IAsyncResult ar)
      {
          UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).udpClient;
          IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).endPoint;

          //End the receive to retrieve the data
          Byte[] receiveBytes = u.EndReceive(ar, ref e);

          //Do some processing
          Console.WriteLine(Encoding.ASCII.GetString(receiveBytes) + "\r\n");

          //Start listening again...
          ReceiveMessages();

      }

      //This listens to the port and calls the Async Callback when data is retrieved
      public static void ReceiveMessages()
      {
          UdpState state = new UdpState();
          state.endPoint = endPoint;
          state.udpClient = udpClient;
          udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), state);

      }
  }

  //UdpState object - records the state of the of the UdpClient
  class UdpState
  {
      public UdpClient udpClient;
      public IPEndPoint endPoint;
  }


Once it's running, from a command prompt enter a TFTP command like TFTP -i localhost GET test.txt and you should see it working - "q" quits.


"It was the day before today.... I remember it like it was yesterday."

-Moleman


GeneralRe: How can I use a parsed UDP byte stream to continually update a GUI form ? Pin
flyingnome3-Aug-07 6:11
flyingnome3-Aug-07 6:11 
GeneralRe: How can I use a parsed UDP byte stream to continually update a GUI form ? Pin
martin_hughes3-Aug-07 7:07
martin_hughes3-Aug-07 7:07 
GeneralRe: How can I use a parsed UDP byte stream to continually update a GUI form ? Pin
flyingnome7-Aug-07 7:53
flyingnome7-Aug-07 7:53 
GeneralRe: How can I use a parsed UDP byte stream to continually update a GUI form ? Pin
martin_hughes7-Aug-07 12:30
martin_hughes7-Aug-07 12:30 
QuestionA error is difficult to understand Pin
nhathoang3-Aug-07 4:04
nhathoang3-Aug-07 4:04 
AnswerRe: A error is difficult to understand Pin
Colin Angus Mackay3-Aug-07 4:11
Colin Angus Mackay3-Aug-07 4:11 
AnswerRe: A error is difficult to understand Pin
Pete O'Hanlon3-Aug-07 4:14
mvePete O'Hanlon3-Aug-07 4:14 
GeneralRe: A error is difficult to understand Pin
nhathoang3-Aug-07 4:18
nhathoang3-Aug-07 4:18 
GeneralRe: A error is difficult to understand Pin
Pete O'Hanlon3-Aug-07 4:29
mvePete O'Hanlon3-Aug-07 4:29 
GeneralRe: A error is difficult to understand Pin
nhathoang3-Aug-07 7:35
nhathoang3-Aug-07 7:35 
AnswerRe: A error is difficult to understand Pin
Luc Pattyn3-Aug-07 5:56
sitebuilderLuc Pattyn3-Aug-07 5:56 
Questionhow to initiate a class stored in string variable Pin
Asif Rehman3-Aug-07 3:32
Asif Rehman3-Aug-07 3:32 
AnswerRe: how to initiate a class stored in string variable Pin
Guffa3-Aug-07 3:36
Guffa3-Aug-07 3:36 
AnswerRe: how to initiate a class stored in string variable Pin
Urs Enzler3-Aug-07 3:58
Urs Enzler3-Aug-07 3:58 
GeneralRe: how to initiate a class stored in string variable Pin
Asif Rehman3-Aug-07 4:31
Asif Rehman3-Aug-07 4:31 
GeneralRe: how to initiate a class stored in string variable Pin
CiNN3-Aug-07 7:55
CiNN3-Aug-07 7:55 
QuestionWhat is Threading ? Pin
Chintan.Desai3-Aug-07 2:49
Chintan.Desai3-Aug-07 2:49 

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.