更改套接字客户端的本地端口 [英] Changing local port of a socket client

查看:317
本文介绍了更改套接字客户端的本地端口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的TCP套接字客户端和服务器应用程序.他们使用IP =本地主机和端口= 33367进行通信.

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

我正在使用SocketSniff检查通过本地主机的数据包.嗅探客户端应用程序时,我注意到每次以相同的过程向服务器发送数据包时,本地端口"都在更改,而远程端口始终是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.

那么,客户端应用程序是否有可能通过固定端口发送数据(如果是,则使用C#?),还是必须每次都为它们分配一个不同的端口?

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?

推荐答案

您可以在调用connect之前绑定套接字.

You can bind the socket before calling connect.

这篇关于更改套接字客户端的本地端口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆