Click here to Skip to main content
15,921,697 members
Home / Discussions / C#
   

C#

 
AnswerRe: toolbar moving Pin
Yusuf28-Feb-09 21:17
Yusuf28-Feb-09 21:17 
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 
Hi,
This is the server code:
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));
        string wel = "Welcome to my test server";
        data = Encoding.ASCII.GetBytes(wel);        
        newsock.SendTo(data, data.Length, SocketFlags.None, tmpRemote);
         listBox1.Items.Add(data);
        ASCIIEncoding asen = new ASCIIEncoding();
        newsock.Send(asen.GetBytes("The string was recieved by the server."));
        Console.WriteLine("\nSent Acknowledgement");
            listBox1.Items.Add("The string was recieved by the server.");         
        newsock.Close();
       }
            catch(Exception e)
           {
                   Console.WriteLine("Error..... " + e.StackTrace);
            }}}

This is Form1.cs where i have called the client
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text; 
using System.Net;
using System.Net.Sockets;
using System.Windows.Forms;
namespace WindowsApplication13
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            Callback();
        }
    
        private void Callback()
        {
            try
            {                
                byte[] data = new byte[1024];
                listBox1.Items.Add("Connecting....");
                IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
 Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                listBox1.Items.Add("Connected");
                data = Encoding.ASCII.GetBytes("welcome");
                listBox1.Items.Add("Transmitting...");
                server.SendTo(data, data.Length, SocketFlags.None, ipep);
             IPEndPoint sender = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 9050);
                EndPoint tmpRemote = (EndPoint)sender;
                // data = new byte[1024];
                int recv = server.ReceiveFrom(data, ref tmpRemote);
      //Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
     listBox1.Items.Add(/*"Message received from {0}:",*/ tmpRemote.ToString());
                //Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
                listBox1.Items.Add(Encoding.ASCII.GetString(data, 0, recv));
           listBox1.Items.Add("Stopping client");
                server.Close();
            }
            catch (Exception e)
            {
                Console.WriteLine("Error..... " + e.StackTrace);
            }}}}

I have sent a string Welcome to the server and this works well
The following lines are displayed in the list box control
But the other listBox1.Items.Add()does not work..
What changes should i make to display
listBox1.Items.Add("Connecting....");
listBox1.Items.Add("Connected");
listBox1.Items.Add("Transmitting...");

GeneralRe: Socket Pin
mrithula81-Mar-09 18:48
mrithula81-Mar-09 18:48 
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 

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.