Click here to Skip to main content
15,920,956 members
Home / Discussions / C#
   

C#

 
GeneralRe: Syntax Advice Pin
Luc Pattyn29-Jan-07 1:08
sitebuilderLuc Pattyn29-Jan-07 1:08 
GeneralRe: Syntax Advice Pin
bobsugar22229-Jan-07 2:24
bobsugar22229-Jan-07 2:24 
GeneralRe: Syntax Advice Pin
Luc Pattyn29-Jan-07 2:47
sitebuilderLuc Pattyn29-Jan-07 2:47 
GeneralRe: Syntax Advice Pin
ShermansLagoon29-Jan-07 3:02
ShermansLagoon29-Jan-07 3:02 
GeneralRe: Syntax Advice Pin
Luc Pattyn29-Jan-07 3:29
sitebuilderLuc Pattyn29-Jan-07 3:29 
GeneralRe: Syntax Advice Pin
Martin#29-Jan-07 1:06
Martin#29-Jan-07 1:06 
Question"PRINTSCREEN" Pin
Amit Agarrwal28-Jan-07 23:56
Amit Agarrwal28-Jan-07 23:56 
QuestionSocket problem with Chat app Pin
GermanDM28-Jan-07 23:30
GermanDM28-Jan-07 23:30 
Hi,
Im writing a very simple network chat app. This is only a chat app for two people over network.
Here is my code:
<br />
public partial class MyChat : Form<br />
    {<br />
        Socket sock;<br />
        Thread receiver;<br />
        static IPAddress localIPAddr;<br />
        static int intPort;<br />
        IPEndPoint multiep;<br />
<br />
        public MyChat()<br />
        {<br />
            InitializeComponent();<br />
<br />
            localIPAddr = IPAddress.Parse(txtHost.Text);<br />
            intPort = Convert.ToInt32(txtPort.Text.ToString());<br />
<br />
            multiep = new IPEndPoint(localIPAddr, 4040);<br />
            sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);            <br />
<br />
            IPEndPoint iep = new IPEndPoint(IPAddress.Any, intPort);<br />
            sock.Bind(iep);<br />
<br />
            sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(localIPAddr));<br />
<br />
            receiver = new Thread(new ThreadStart(packetReceive));<br />
            receiver.IsBackground = true;<br />
            receiver.Start();          <br />
        }<br />
<br />
        void packetReceive()<br />
        {<br />
            EndPoint ep = (EndPoint)multiep;<br />
            byte[] data = new byte[1024];<br />
            string stringData;<br />
            int recv;<br />
            while (true)<br />
            {<br />
                recv = sock.ReceiveFrom(data, ref ep);<br />
                stringData = Encoding.ASCII.GetString(data, 0, recv);<br />
                //results.Items.Add("from " + ep.ToString() + ":  " + stringData);<br />
                rtxtMsgWindow.AppendText("from " + ep.ToString() + ":  " + stringData);<br />
            }<br />
        }<br />
<br />
        private void btnExit_Click(object sender, EventArgs e)<br />
        {<br />
            receiver.Abort();<br />
            sock.Close();<br />
            Close();   <br />
        }        <br />
<br />
        private void txtMessage_KeyPress(object sender, KeyPressEventArgs e)<br />
        {<br />
            if (e.Handled = e.KeyChar == 13)<br />
            {<br />
                byte[] message = Encoding.ASCII.GetBytes(txtMessage.Text);<br />
                txtMessage.Clear();<br />
                sock.SendTo(message, SocketFlags.None, multiep);<br />
            }<br />
        }<br />
    }<br />
<br />


Problem is i get the following socket exception The requested address is not valid in its context at the line of code i made bold above.

The specified ip address would be my own ip address to test and see if the message gets posted. If this is the problem is there any other way i could get around this maybe a different way of socket programming maybe using tcpclient or something?

Im a noob to sockets or network programming pls help thx Smile | :)
Regards
QuestionWeb Services Interopelability Issue Pin
blackjack215028-Jan-07 22:54
blackjack215028-Jan-07 22:54 
AnswerRe: Web Services Interopelability Issue Pin
blackjack215029-Jan-07 22:50
blackjack215029-Jan-07 22:50 
QuestionClosing form event Pin
george ivanov28-Jan-07 21:55
george ivanov28-Jan-07 21:55 
AnswerRe: Closing form event Pin
engsrini28-Jan-07 22:10
engsrini28-Jan-07 22:10 
AnswerRe: Closing form event Pin
Rahul.RK29-Jan-07 0:01
Rahul.RK29-Jan-07 0:01 
GeneralRe: Closing form event Pin
george ivanov29-Jan-07 3:58
george ivanov29-Jan-07 3:58 
QuestionMicrosoft.Office.Interop.Word Pin
zt.Prog28-Jan-07 21:03
zt.Prog28-Jan-07 21:03 
AnswerRe: Microsoft.Office.Interop.Word Pin
Michael Sterk28-Jan-07 21:17
Michael Sterk28-Jan-07 21:17 
GeneralRe: Microsoft.Office.Interop.Word Pin
zt.Prog28-Jan-07 21:50
zt.Prog28-Jan-07 21:50 
GeneralRe: Microsoft.Office.Interop.Word Pin
szukuro29-Jan-07 0:49
szukuro29-Jan-07 0:49 
GeneralRe: Microsoft.Office.Interop.Word Pin
zt.Prog29-Jan-07 1:09
zt.Prog29-Jan-07 1:09 
GeneralRe: Microsoft.Office.Interop.Word Pin
s mohit1-Jun-12 20:39
s mohit1-Jun-12 20:39 
AnswerRe: Microsoft.Office.Interop.Word Pin
Abisodun29-Jan-07 2:52
Abisodun29-Jan-07 2:52 
Questionhow do i remove header and footer before i start to print the document Pin
Support12328-Jan-07 20:56
Support12328-Jan-07 20:56 
AnswerRe: how do i remove header and footer before i start to print the document Pin
andre_swnpl29-Jan-07 0:49
andre_swnpl29-Jan-07 0:49 
GeneralRe: how do i remove header and footer before i start to print the document Pin
Support12329-Jan-07 1:44
Support12329-Jan-07 1:44 
GeneralRe: how do i remove header and footer before i start to print the document Pin
andre_swnpl29-Jan-07 1:58
andre_swnpl29-Jan-07 1:58 

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.