1

Is it possible to send data from 127.0.0.1:7000 to 127.0.0.1:8000 ? I am getting socket error 10049 which is invalid address.

sockaddr_in sin;
memset((char*)&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr = 16777343; //127.0.0.1
sin.sin_port = 16415;//8000
int _ret = ::sendto(sock, Buff, Len, 0, (sockaddr*)&sin, sizeof(sin));
Richard
  • 106,783
  • 21
  • 203
  • 265
Tahlil
  • 2,680
  • 6
  • 43
  • 84
  • How are you using those addresses – when working with the APIs the port number is a different parameter to the machine address, Ie: please show your code. – Richard Mar 09 '15 at 09:07
  • Added the code for sending the data. Thanks. – Tahlil Mar 09 '15 at 09:18

2 Answers2

1
sin.sin_addr = 16777343; //127.0.0.1

I think you might want to check that.

Here 127×255×255×255 + 1 is 2105834626.

Use the right functions to perform IP address decoding, don't do it yourself: there are too many edge cases (eg. signed/unsigned) to get caught on.

Richard
  • 106,783
  • 21
  • 203
  • 265
0

sin.sin_port = 16415;//8000

this is wrong, sin_port must be in network format the correct code should be:

sin.sin_port = htons(16415);//8000