Note that there are some explanatory texts on larger screens.

plurals
  1. PO.Net Socket not streaming from correct port?
    primarykey
    data
    text
    <p>C# .Net application which connects to five different data streams. The data streams are all in the same plaintext format, but have information from different areas. The application creates an array of custom objects, which contains sockets. Each socket connects to its IP/port (same IP, different ports) with no problems. However, when I read data off each socket, I'm getting the same data stream, from the first port number (in range, 10085-10089). For instance, I read data off the socket that's connected to 10088, but I get data from 10085.</p> <p>The IP/port is grabbed from a database, so I deleted all but the record for port 10088, so the array created has only one object; there is only one socket connection, to port 10088. But I'm still getting only data from 10085.</p> <p>I've viewed the data from each port through putty; the data is definitely different. Any idea why I'm getting the same data no matter what port a socket's connected to?</p> <p>This is some simpler code that replicates the problem:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Sockets; using System.Net; namespace MultipleFeedConnectionsTest { class Program { static void Main(string[] args) { Socket[] sockets; IPAddress ipAddress; IPAddress currentIP; int portNumber = 10085; ipAddress = IPAddress.Parse("xxx.xxx.xxx.xxx"); // changed the IP currentIP = IPAddress.Parse("192.168.5.122"); sockets = new Socket[5]; for (int counter = 0; counter &lt; 5; counter++) { if (counter != 1) { sockets[counter] = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); sockets[counter].Bind(new IPEndPoint(currentIP, portNumber + counter)); sockets[counter].Connect(new IPEndPoint(ipAddress, portNumber + counter)); } } while (true) { for (int counter = 0; counter &lt; 5; counter++) { if (counter != 1) { byte[] receivedData = new byte[255]; NetworkStream stream = new NetworkStream(sockets[counter]); stream.Read(receivedData, 0, 255); Console.WriteLine("FEED " + (portNumber + counter)); Console.WriteLine(Encoding.ASCII.GetString(receivedData)); } } } } } } </code></pre> <p>The above code outputs the same data from each socket. Again, when I access these through putty, they are different.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload