Adam Aji Nugroho
Adam Aji Nugroho

Reputation: 11

Different port Socket C# for sending and receive

i'm using UDP async socket in C#.net and i want to make the server and a client communicate in different port for sending and receive,

is it possible??

Upvotes: 1

Views: 2718

Answers (4)

Some programmer dude
Some programmer dude

Reputation: 409216

In the client bind the socket to port A, and in the client bind to port B. It's as simple as that. The server shouldn't really know A, but get it from the messages it receives messages from the client (using something like ReceiveFrom.

Remember that using UDP, the client has to be the first to send messages, otherwise it's not really a client-server system but more distributed system.

Upvotes: 1

Paul Farry
Paul Farry

Reputation: 4768

If you were using TCP rather than UDP as part of the constructor of the TCPClient you can specify which EndPoint you want the outgoing connection to use.

Upvotes: 0

Marlon
Marlon

Reputation: 20312

It's not possible to do this, since an endpoint consists of only one IP address and one port number. You would need to use two different sockets and establish two connections with the server in order to use port A and port B.

Upvotes: 0

Scott Chamberlain
Scott Chamberlain

Reputation: 127583

This is exactly how it happens already. The source port for a client is a random port chosen by the OS.

Upvotes: 0

Related Questions