Click here to Skip to main content
15,916,378 members
Home / Discussions / C#
   

C#

 
QuestionSocket Pin
mrithula828-Feb-09 20:39
mrithula828-Feb-09 20:39 
AnswerRe: Socket Pin
Yusuf28-Feb-09 21:22
Yusuf28-Feb-09 21:22 
GeneralRe: Socket Pin
mrithula828-Feb-09 22:47
mrithula828-Feb-09 22:47 
GeneralRe: Socket Pin
0x3c028-Feb-09 23:23
0x3c028-Feb-09 23:23 
GeneralRe: Socket Pin
mrithula828-Feb-09 23:39
mrithula828-Feb-09 23:39 
GeneralRe: Socket Pin
0x3c028-Feb-09 23:54
0x3c028-Feb-09 23:54 
GeneralRe: Socket Pin
mrithula81-Mar-09 17:22
mrithula81-Mar-09 17:22 
GeneralRe: Socket Pin
mrithula81-Mar-09 18:48
mrithula81-Mar-09 18:48 
Hi,
I have made some changes to the above code and i have made the client and the server to communicate...
Now i need to perform a small check...
i have sent a string hello from the client to server...
the string is received in the server...Once it is received i want to check whether the received string is right...if it is right it must send another message to the client...So i used a" if" loop....When i use this loop im not able to receive the message from the server...
Please tell me the changes
using System;
using System.Net;
using System.Net.Sockets;
using System.Text;

public class UdpServer
{
    public static void Main()
    {
        try
        {
        int recv;
        byte[] data = new byte[1024];
        IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);

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

        newsock.Bind(ipep);
        Console.WriteLine("Waiting for a client...");

        IPEndPoint sender = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
        EndPoint tmpRemote = (EndPoint)(sender);

        recv = newsock.ReceiveFrom(data, ref tmpRemote);

        Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
        Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));//hello is received
 
        if (Encoding.ASCII.GetString(data)=="hello")
        {
            data = new byte[1024];
            string ss = "Welcome to the Server";
            data = Encoding.ASCII.GetBytes(ss);
            newsock.SendTo(data, data.Length, SocketFlags.None, tmpRemote);
        }

        Console.WriteLine("\nSent Acknowledgement");
        newsock.Close();
    }  
       
            catch(Exception e)
           {
                   Console.WriteLine("Error..... " + e.StackTrace);
            }
    }
}

QuestionHow to Copy Form in Project ? Pin
E_Gold28-Feb-09 20:12
E_Gold28-Feb-09 20:12 
AnswerRe: How to Copy Form in Project ? Pin
Yusuf28-Feb-09 21:26
Yusuf28-Feb-09 21:26 
GeneralRe: How to Copy Form in Project ? Pin
E_Gold28-Feb-09 22:13
E_Gold28-Feb-09 22:13 
GeneralRe: How to Copy Form in Project ? Pin
Yusuf1-Mar-09 3:28
Yusuf1-Mar-09 3:28 
AnswerRe: How to Copy Form in Project ? Pin
Henry Minute1-Mar-09 1:51
Henry Minute1-Mar-09 1:51 
QuestionAccess Database crashing on load in Vista Pin
Hitchic0528-Feb-09 17:22
Hitchic0528-Feb-09 17:22 
AnswerRe: Access Database crashing on load in Vista [modified] Pin
Douglas Troy1-Mar-09 7:18
Douglas Troy1-Mar-09 7:18 
AnswerRe: Access Database crashing on load in Vista Pin
Razvan Dimescu1-Mar-09 22:42
Razvan Dimescu1-Mar-09 22:42 
GeneralRe: Access Database crashing on load in Vista Pin
Douglas Troy2-Mar-09 7:18
Douglas Troy2-Mar-09 7:18 
QuestionMonitor and scan internet files Pin
Ghaith Hachem28-Feb-09 12:09
Ghaith Hachem28-Feb-09 12:09 
AnswerRe: Monitor and scan internet files Pin
abdul jalil1-Mar-09 3:48
abdul jalil1-Mar-09 3:48 
GeneralRe: Monitor and scan internet files Pin
Ghaith Hachem1-Mar-09 4:04
Ghaith Hachem1-Mar-09 4:04 
QuestionReading specif Excel sheet headers Pin
alvas8928-Feb-09 11:09
alvas8928-Feb-09 11:09 
AnswerRe: Reading specif Excel sheet headers Pin
Calin Tatar28-Feb-09 16:12
Calin Tatar28-Feb-09 16:12 
GeneralRe: Reading specif Excel sheet headers Pin
alvas893-Mar-09 9:08
alvas893-Mar-09 9:08 
AnswerRe: Reading specif Excel sheet headers Pin
0x3c01-Mar-09 0:03
0x3c01-Mar-09 0:03 
GeneralRe: Reading specif Excel sheet headers Pin
alvas893-Mar-09 9:12
alvas893-Mar-09 9:12 

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.