how to change client source port every connect in FRDMK64

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

how to change client source port every connect in FRDMK64

737 次查看
sudhakarp
Contributor V

Hi,

i am using KDS3.0 and KSDK1.3.0 example. i am using FRDMk64 board and ethernet_to_serial example.in my application code my device act as Client so i will connect to server. its working fine. but every disconnect and connect my source port should change for that what i want to do..? where i can see source port assignment ..? actually i want to increase the source port number for every connection.how to do that..?

NOTE: i want to change device PORT number not server PORT number.

regards,

sudhakar p

标签 (1)
0 项奖励
回复
1 回复

487 次查看
Carlos_Musich
NXP Employee
NXP Employee

Hi

if you are using TCP sockets you must have a structure of type sockaddr_in. In field sin_port you may indicate the destination port. Refer to the snippet below.

#define DESTPORT 1030

    sockaddr_in    addr;

    addr.sin_family      = AF_INET;

    addr.sin_port        = 0;

    addr.sin_addr.s_addr = INADDR_ANY;

        error = bind(sock, &addr, sizeof(addr));

    addr.sin_port        = DESTPORT;

    addr.sin_addr.s_addr = IPADDR(192,168,1,132); //Server address

     error = connect(sock, &addr, sizeof(addr));

Regards,

Carlos

0 项奖励
回复