Click here to Skip to main content
15,905,607 members
Home / Discussions / C#
   

C#

 
GeneralRe: Installation Pin
J a a n s29-Apr-08 1:25
professionalJ a a n s29-Apr-08 1:25 
GeneralRe: Installation Pin
Vikram A Punathambekar29-Apr-08 2:17
Vikram A Punathambekar29-Apr-08 2:17 
QuestionHow to use regular expression Pin
Exelioindia29-Apr-08 0:07
Exelioindia29-Apr-08 0:07 
AnswerRe: How to use regular expression Pin
c242329-Apr-08 0:48
c242329-Apr-08 0:48 
GeneralRe: How to use regular expression Pin
Exelioindia29-Apr-08 1:05
Exelioindia29-Apr-08 1:05 
AnswerRe: How to use regular expression Pin
Pete O'Hanlon29-Apr-08 0:51
mvePete O'Hanlon29-Apr-08 0:51 
GeneralRe: How to use regular expression Pin
Exelioindia29-Apr-08 1:03
Exelioindia29-Apr-08 1:03 
GeneralTCP Socket Exception , two ports / one IP address Pin
Rick van Woudenberg28-Apr-08 23:40
Rick van Woudenberg28-Apr-08 23:40 
Dear all,

I'm trying to bind two ports to one IP address. In my first method I bind a port ( 31010 ) to IpAddress.Any

                Int32 port = 31010;<br />
                IPAddress localAddr = IPAddress.Any;<br />
                //TcpListener server = new TcpListener(port);<br />
                server = new TcpListener(localAddr, port);<br />
                server.ExclusiveAddressUse = false;<br />
                // Start listening for client requests.<br />
                server.Start();<br />
<br />
                // Buffer for reading data<br />
                Byte[] bytes = new Byte[256];<br />
                String data = null;<br />
<br />
                // Enter the listening loop.<br />
                while (true)<br />
                {<br />
                    // Perform a blocking call to accept requests.<br />
                    // You could also user server.AcceptSocket() here.<br />
                    client = server.AcceptTcpClient();<br />
                    client.ExclusiveAddressUse = false;<br />
                    //blah blah the rest ... <snip><br />
<br />
                }</snip>



This works fine in itself. The application is listening on this port and receives data which is processed happily.

However, I add another method to bind another port ( 31009 ) which I call after the first one :

        private static void SendMessageToMessenger(string data)<br />
        {<br />
            //create the socket instance...<br />
            mm_socClient = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);<br />
<br />
            // get the remote IP address...<br />
            IPAddress ip = IPAddress.Any;<br />
            mm_socClient.ExclusiveAddressUse = false;<br />
            int iPortNo = 31009;<br />
            //create the end point <br />
            IPEndPoint ipEnd = new IPEndPoint(ip.Address, iPortNo);<br />
            //connect to the remote host...<br />
            mm_socClient.Connect(ipEnd);<br />
<br />
            Object objData = data;<br />
            byte[] byData = System.Text.Encoding.ASCII.GetBytes(objData.ToString());<br />
            mm_socClient.Send(byData);<br />
<br />
            // End string<br />
<br />
            mm_socClient.Disconnect(true);<br />
        }


And then it goes wrong. It throws an Exception saying :

SocketException: Only one usage of each socket address (protocol/network address/port) is normally permitted

I know that the first method is performing a blocking call to receive data, but I'm assuming this blocking call is done for the port and not the IP address but I could be wrong there. Anyhow, it won't allow me to bind a different port to the same IP address, although I set the ExclusiveAddressUse to false.

Can anyone help me out here ?

Cheers,
GeneralRe: TCP Socket Exception , two ports / one IP address Pin
Bert delaVega29-Apr-08 5:07
Bert delaVega29-Apr-08 5:07 
GeneralNumericUpDown control in ToolStrip Pin
mcbass28-Apr-08 23:00
mcbass28-Apr-08 23:00 
GeneralRe: NumericUpDown control in ToolStrip Pin
John_Adams29-Apr-08 1:04
John_Adams29-Apr-08 1:04 
GeneralRe: NumericUpDown control in ToolStrip Pin
mcbass29-Apr-08 2:28
mcbass29-Apr-08 2:28 
GeneralRe: NumericUpDown control in ToolStrip Pin
PubLee23-Jan-10 0:16
PubLee23-Jan-10 0:16 
GeneralRunning code in a different appdomain Pin
laserbaronen28-Apr-08 22:59
laserbaronen28-Apr-08 22:59 
GeneralRe: Running code in a different appdomain Pin
Simon P Stevens28-Apr-08 23:27
Simon P Stevens28-Apr-08 23:27 
GeneralRe: Running code in a different appdomain Pin
Simon P Stevens28-Apr-08 23:31
Simon P Stevens28-Apr-08 23:31 
GeneralRe: Running code in a different appdomain Pin
laserbaronen29-Apr-08 1:25
laserbaronen29-Apr-08 1:25 
GeneralRe: Running code in a different appdomain Pin
Simon P Stevens29-Apr-08 1:59
Simon P Stevens29-Apr-08 1:59 
GeneralAdding header to the print of DevExpress Grid Control Pin
Chapooki28-Apr-08 22:58
Chapooki28-Apr-08 22:58 
GeneralRe: Adding header to the print of DevExpress Grid Control Pin
Bert delaVega29-Apr-08 8:24
Bert delaVega29-Apr-08 8:24 
GeneralRe: Adding header to the print of DevExpress Grid Control Pin
Chapooki29-Apr-08 18:10
Chapooki29-Apr-08 18:10 
GeneralDataGridView Issue Pin
Member 400849228-Apr-08 22:38
Member 400849228-Apr-08 22:38 
GeneralRe: DataGridView Issue Pin
dan!sh 28-Apr-08 23:20
professional dan!sh 28-Apr-08 23:20 
GeneralRe: DataGridView Issue Pin
Member 400849229-Apr-08 0:44
Member 400849229-Apr-08 0:44 
GeneralRe: DataGridView Issue Pin
dan!sh 29-Apr-08 1:16
professional dan!sh 29-Apr-08 1:16 

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.