Began to study WinSock, in this regard, many questions have arisen.
First : There is a code

#include <winsock2.h> __fastcall TForm3::TForm3(TComponent* Owner) : TForm(Owner) { WSADATA wsd; if (WSAStartup(MAKEWORD(2,0), &wsd)!=0) { Memo1->Lines->Add("Ошибка старта сокета"); } else { Memo1->Lines->Add("Библиотека Работает"); SOCKET S; struct sockaddr_in servaddr; S=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); servaddr.sin_family=AF_INET; servaddr.sin_port=htons(28960); //порт сервера servaddr.sin_addr.s_addr=inet_addr("IPшник.до.серва.ка"); char *buf = "\xff\xff\xff\xff getstatus"; S=send(S,buf,sizeof(buf),0); // делал и просто send(S,buf,sizeof(buf),0); } } 

I registered everything there - IPs, ports, I launch the program, and nothing happens - why? More precisely in the memo writes "Library Works" and that's it. Internet monitor does not register new opened ports, the sniffer does not register any activity (sending a packet to the server). How to "activate" it? To do this, you need to create another socket. "outgoing"?

Second , how can I do this in the future, so that when a certain button is pressed, a certain info server is sent to the server?

  • Everything, with everything figured out, you can close the question :) - DizzWebS

1 answer 1

For UDP, you must use sendto (), not send ().

  • And in order to receive information from the server, you need to open another socket and bind the port on your computer? And in general - in theory, when creating a socket, my program should open the ip and the port from which it will send? - DizzWebS
  • figured out :) - DizzWebS