locked
how to create two or more client connection with the server or two or more server connection with the client. with same server and same client

    Frage

  • hi experts,

    In socket programming can there be only one listening port or mutiple 

    how can a client create mutiple connection with the server.

    or how can a server create mutiple connection with the client

    can a same client talk to server on different listening port 

     

    Mittwoch, 30. Juni 2010 11:11

Antworten

  • thanks Cristian.

    u mean to say that same client and same server can create mutiple connection listening on different different port of server. but the problem is if my connection already establised with server at 5000 port then how can i create a new connection with server on different port because the previous connection is still  alive.

    • Als Antwort markiert luckyforu2006 Donnerstag, 1. Juli 2010 07:04
    Mittwoch, 30. Juni 2010 11:48
  •  

    Just creating a new TcpClient() will have the system create one with your client's IP and a new port number. If you use Socket, you achieve the same with mySocket.Bind(new IPEndpoint(IPAddress.Any, 0)).The zero means "take the next free port".

    When you connect, the destination will be server IP, port 5000, but the client port will be different for each client or socket.

    Cristian.

    • Als Antwort markiert luckyforu2006 Donnerstag, 1. Juli 2010 07:04
    Mittwoch, 30. Juni 2010 14:04

Alle Antworten

  • - you can have several listening ports on a server (but normally you have one per "service", like port 80 for HTTP, 8080 for HTTPS etc.)

    - a (TCP) connection is defined by 4 numbers: client IP, client port, server IP, server port. As long as any of these 4 is different, it is a different connection (in other words, although all clients are connecting to the same server IP and port, they all will have different IP and / or port numbers) and the server can keep them apart (it will create one socket for each connection)

    Cristian.

    Mittwoch, 30. Juni 2010 11:27
  • thanks Cristian.

    u mean to say that same client and same server can create mutiple connection listening on different different port of server. but the problem is if my connection already establised with server at 5000 port then how can i create a new connection with server on different port because the previous connection is still  alive.

    • Als Antwort markiert luckyforu2006 Donnerstag, 1. Juli 2010 07:04
    Mittwoch, 30. Juni 2010 11:48
  • Is it possible to create to new connection  from server to client. if yes can anybody provide me a sample code.
    Mittwoch, 30. Juni 2010 11:52
  •  

    Just creating a new TcpClient() will have the system create one with your client's IP and a new port number. If you use Socket, you achieve the same with mySocket.Bind(new IPEndpoint(IPAddress.Any, 0)).The zero means "take the next free port".

    When you connect, the destination will be server IP, port 5000, but the client port will be different for each client or socket.

    Cristian.

    • Als Antwort markiert luckyforu2006 Donnerstag, 1. Juli 2010 07:04
    Mittwoch, 30. Juni 2010 14:04