Click here to Skip to main content
15,880,427 members
Home / Discussions / C#
   

C#

 
AnswerRe: Simple Threading (VS 2005) Example Pin
Luc Pattyn25-Feb-09 1:13
sitebuilderLuc Pattyn25-Feb-09 1:13 
QuestionEdit of C# DLL file Pin
HatakeKaKaShi24-Feb-09 20:24
HatakeKaKaShi24-Feb-09 20:24 
AnswerRe: Edit of C# DLL file Pin
WinSolution24-Feb-09 20:37
WinSolution24-Feb-09 20:37 
GeneralRe: Edit of C# DLL file Pin
HatakeKaKaShi24-Feb-09 20:47
HatakeKaKaShi24-Feb-09 20:47 
QuestionISO 8583 [modified] Pin
astrovirgin24-Feb-09 18:43
astrovirgin24-Feb-09 18:43 
AnswerRe: ISO 8583 Pin
N a v a n e e t h24-Feb-09 18:59
N a v a n e e t h24-Feb-09 18:59 
AnswerRe: ISO 8583 Pin
Tim Speekenbrink12-May-09 6:35
Tim Speekenbrink12-May-09 6:35 
QuestionSocket Pin
mrithula824-Feb-09 18:35
mrithula824-Feb-09 18:35 
Hi,
I have used the following code for Tcp client server communication ..
It works well...
I want to do the same for the Udp also...so i replaced Udp instead of Tcp...

It gives me the error:
The type or namespace name UdpListener could not be found(are you missing a using directive or a assembly reference)

Code for tcp server
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.Runtime;
using System.Text;
public class Server
{
    public Server()
    {
       
    }
    public static void Main()
    {

        try
        {
            IPAddress ipAd = IPAddress.Parse("192.168.1.32"); //use local m/c IP address, and use the same in the client
            TcpListener myList = new TcpListener(ipAd, 8006);

            myList.Start();

            Console.WriteLine("The server is running at port 8006...");
           
            Console.WriteLine("The local End point is  :" + myList.LocalEndpoint);
            Console.WriteLine("Waiting for a connection.....");

            Socket s = myList.AcceptSocket();
            Console.WriteLine("Connection accepted from " + s.RemoteEndPoint);

            byte[] b = new byte[100];
            int k = s.Receive(b);
            Console.WriteLine("Recieved...");
            for (int i = 0; i < k; i++)
                Console.Write(Convert.ToChar(b[i]));

            ASCIIEncoding asen = new ASCIIEncoding();
            s.Send(asen.GetBytes("The string was recieved by the server."));
            Console.WriteLine("\nSent Acknowledgement");

            s.Close();
            myList.Stop();

        }

        catch (Exception e)
        {
            Console.WriteLine("Error..... " + e.StackTrace);
        }
    }
   
}

I replaced UdpListener instead of TcpListener...
Is that right?
Code for Tcp client
using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Diagnostics;
using System.Text;
public class Client
{
    public Client()
    {
       
    }
    public static void Main()
    {

        try
        {
            TcpClient tcpclnt = new TcpClient();
            Console.WriteLine("Connecting.....");
            tcpclnt.Connect("192.168.1.32", 8006); // use the ipaddress as in the server program

            Console.WriteLine("Connected");
            Console.Write("Enter the string to be transmitted : ");

            String str = Console.ReadLine();
            Stream stm = tcpclnt.GetStream();

            ASCIIEncoding asen = new ASCIIEncoding();
            byte[] ba = asen.GetBytes(str);
            Console.WriteLine("Transmitting.....");

            stm.Write(ba, 0, ba.Length);

            byte[] bb = new byte[100];
            int k = stm.Read(bb, 0, 100);
           
            for (int i = 0; i < k; i++)
                Console.Write(Convert.ToChar(bb[i]));

            tcpclnt.Close();
        }

        catch (Exception e)
        {
            Console.WriteLine("Error..... " + e.StackTrace);
        }
    }

}

What changes should i do to make it work for Udp ?
Please help with this....
AnswerRe: Socket Pin
N a v a n e e t h24-Feb-09 19:04
N a v a n e e t h24-Feb-09 19:04 
QuestionXSLT2 Functions Exception in C# Pin
C. Hariharan24-Feb-09 18:34
C. Hariharan24-Feb-09 18:34 
AnswerRe: XSLT2 Functions Exception in C# Pin
N a v a n e e t h24-Feb-09 19:05
N a v a n e e t h24-Feb-09 19:05 
AnswerRe: XSLT2 Functions Exception in C# Pin
Pete O'Hanlon24-Feb-09 21:57
mvePete O'Hanlon24-Feb-09 21:57 
GeneralRe: XSLT2 Functions Exception in C# Pin
C. Hariharan24-Feb-09 22:27
C. Hariharan24-Feb-09 22:27 
GeneralRe: XSLT2 Functions Exception in C# Pin
Pete O'Hanlon25-Feb-09 4:05
mvePete O'Hanlon25-Feb-09 4:05 
GeneralRe: XSLT2 Functions Exception in C# Pin
C. Hariharan25-Feb-09 19:23
C. Hariharan25-Feb-09 19:23 
Questionusing vb and c# in one solution simoltaneously Pin
lili.zd24-Feb-09 17:53
lili.zd24-Feb-09 17:53 
AnswerRe: using vb and c# in one soluton simoltaneously Pin
Xmen Real 24-Feb-09 17:56
professional Xmen Real 24-Feb-09 17:56 
GeneralRe: using vb and c# in one soluton simoltaneously Pin
lili.zd25-Feb-09 3:07
lili.zd25-Feb-09 3:07 
GeneralRe: using vb and c# in one soluton simoltaneously Pin
Xmen Real 25-Feb-09 4:12
professional Xmen Real 25-Feb-09 4:12 
GeneralRe: using vb and c# in one soluton simoltaneously Pin
lili.zd25-Feb-09 4:19
lili.zd25-Feb-09 4:19 
QuestionImage processing in C# Pin
nocpp24-Feb-09 17:44
nocpp24-Feb-09 17:44 
AnswerRe: Image processing in C# Pin
N a v a n e e t h24-Feb-09 19:07
N a v a n e e t h24-Feb-09 19:07 
AnswerRe: Image processing in C# Pin
Christian Graus24-Feb-09 19:22
protectorChristian Graus24-Feb-09 19:22 
Questionremove escape sequence [modified] Pin
LiYS24-Feb-09 17:35
LiYS24-Feb-09 17:35 
AnswerRe: remove escape sequence Pin
aaCog24-Feb-09 17:39
aaCog24-Feb-09 17:39 

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.