Changing local port of a socket client

拜拜、爱过 提交于 2019-12-13 04:12:16

问题


I have a simple TCP socket client and server application. They are communicating using IP = localhost and port = 33367.

I'm using SocketSniff to examine my packets going through localhost. While sniffing the client app, I noticed that every time I'm sending a packet to the server in the same process, the "local port" is changing, while remote port is always 33367.

So, is it possible for the client apps to send their data through a fixed port (if so, how in C#?) or do they have to get assigned a different port each time?


回答1:


You can bind the socket before calling connect.



来源:https://stackoverflow.com/questions/4788004/changing-local-port-of-a-socket-client

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!