|
|
|
|
||||||
| comp.protocols.tcp-ip TCP and IP network protocols. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
Hello everyone,
I have this code for TCPListenPort. The code works fine, but my manager is asking me to establish multiple connections to the same port. How can i acheive that below is my code Int32 port = Int32.Parse(ConfigurationManager.AppSettings["port"]); IPAddress localAddr = IPAddress.Parse(ConfigurationManager.AppSettings["IpAddress"]); TcpListener server = new TcpListener(localAddr, port); server.Start(); Byte[] bytes = new Byte[256]; String data = null; // Enter the listening loop. while (true) { // Perform a blocking call to accept requests. TcpClient client = server.AcceptTcpClient(); remotePoint = client.Client.RemoteEndPoint.ToString(); data = null; NetworkStream stream = client.GetStream(); int i; // Loop to receive all the data sent by the clie nt. while ((i = stream.Read(bytes, 0, bytes.Length)) != 0) { // Translate data bytes to a ASCII string. data = System.Text.Encoding.ASCII.GetString(bytes, 0, i); // Process the data sent by the client. data = data.ToUpper(); byte[] msg = System.Text.Encoding.ASCII.GetBytes(data); if (msg.Length > 5) { byte[] msgClone = writeClassLibrary.getReturnBytes.ReturnData(_sessi onDisplay, msg); stream.Write(msgClone, 0, msgClone.Length); } } // Shutdown and end connection client.Close(); } |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
On Fri, 05 Oct 2007 23:06:53 -0700, vinki wrote:
> Hello everyone, > > > I have this code for TCPListenPort. The code works fine, but my manager > is > asking me to establish multiple connections to the same port. How can i > acheive that > Get a good book about writing tcp/ip servers on Windows. It's trivial on Unix with fork(). On Windows, you need to use threads. Not hard, but not completely trivial either. HTH, M4 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
On Oct 6, 2:06 am, vinki <nitugup...@gmail.com> wrote:
> Hello everyone, > > I have this code for TCPListenPort. The code works fine, but my > manager is > asking me to establish multiple connections to the same port. How can > i > acheive that > A TCP connection is identified by the combination of source ip, source port, destination ip and destination port. Use a different source port number to establish multiple connections to the same destination port. -- VisualEther - http://www.EventHelix.com/VisualEther Generate sequence diagram from Wireshark (Ethereal) |
|
![]() |
| Outils de la discussion | |
|
|