Problems with sockets and HTTP server

eliott
Posts: 18
Joined: Sat Mar 28, 2020 11:57 am

Problems with sockets and HTTP server

Postby eliott » Mon Jan 25, 2021 8:19 pm

Hello,

I'm using ESP http server for my application with multiple web pages (html, png, js, css...).

I'm also using UDP client and server. I noticed that after 4 http calls I'm unable to open udp client socket.

This is my script:

-> HTTP server host a page called "/devicescan", the javascript call wait until 5 seconds for timeout
-> On the HTTP "get handler": an UDP server is openned on port 2000
-> Then and UDP client is openned and send a string to all other devices on the network via IP 192.168.1.255
-> UDP client is immediately closed
-> If the devices are present they answer back to the ESP on port 2000.
-> The UDP server wait for answers during two seconds and generate a json array.
-> After 2 seconds the answer is transfered back to the HTTP server.

For the example I receive this:

Code: Select all

{"scanlist":[{"name":"Dev1","ip":"192.168.1.193"},{"name":"Dev2","ip":"192.168.1.208"},{"name":"Dev3","ip":"192.168.1.221"}]}
The page "/devicescan" works 4 times, but after this I receive this error: "UDP CLIENT: unable to create socket: errno 23"

I also tryed to use different port for client/server (eg 1800 and 1900).

If I wait a while, this is working again. I don't think I forgot to close the UDP socket, but maybe I'm reaching a limit somewhere or maybe the HTTP socket are not closed properely. How I can monitor this ?

I also noticed that I have a similar issue when I'm using the HTTP client.

Please find my code below:

get_handler function for the page /devicescann:

Code: Select all

static void page_devicescan(httpd_req_t *req)
{
	char data[768]; //!\ 66 chars par device * 10 = 660 + marges
	sprintf(data,"{\"scanlist\":[");
	udp_server_start(data, sizeof(data));
	strcat(data,"]}");
	display_page(req, data, strlen(data));
}
UDP client/server combined

Code: Select all

#define PORT_CLIENT 1900
#define PORT_SERVER 1800

static const char *TAGCLIENT = "[UDP CLIENT]";
static const char *TAGSERVER = "[UDP SERVER]";
static const char *payload = "UDP /NOTIFY-V5\r\n";

static esp_err_t udp_client_receive()
{
    char addr_str[128];
    int addr_family;
    int ip_protocol;

	char *HOST_IP_ADRESS;
	
	HOST_IP_ADRESS=get_sta_ip();
	uint8_t i;
	
	for(i=strlen(HOST_IP_ADRESS); i>5; i--)
	{
		if(*(HOST_IP_ADRESS+i)=='.') break;
	}
	
	if(i==5)
	{
		ESP_LOGI(TAGCLIENT, "Can't match network with IP %s",HOST_IP_ADRESS);
		return ESP_FAIL;	
	}
	else
	{
		memcpy((HOST_IP_ADRESS+i+1),"255\0",4);
		ESP_LOGI(TAGCLIENT, "Network is %s",HOST_IP_ADRESS);

		struct sockaddr_in dest_addr;
		dest_addr.sin_addr.s_addr = inet_addr(HOST_IP_ADRESS);
		dest_addr.sin_family = AF_INET;
		dest_addr.sin_port = htons(PORT_CLIENT);
		addr_family = AF_INET;
		ip_protocol = IPPROTO_IP;
		inet_ntoa_r(dest_addr.sin_addr, addr_str, sizeof(addr_str) - 1);

		int sock = socket(addr_family, SOCK_DGRAM, ip_protocol);
		if (sock < 0) 
		{
			ESP_LOGE(TAGCLIENT, "Unable to create socket: errno %d", errno);
			return ESP_FAIL;
		}
		else
		{
			ESP_LOGI(TAGCLIENT, "Socket created, sending to %s:%d", HOST_IP_ADRESS, PORT_CLIENT);

			int err = sendto(sock, payload, strlen(payload), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
			if (err < 0) 
			{
				ESP_LOGE(TAGCLIENT, "Error occurred during sending: errno %d", errno);
			}
			ESP_LOGI(TAGCLIENT, "Message sent");
			ESP_LOGI(TAGCLIENT, "Shutting down socket.");
			return ESP_OK;
		}
	
		shutdown(sock, 0);
		close(sock);
	}
}

void udp_server_start(char *scandata, uint16_t max_scandata_len)
{

	int32_t l_free;
	uint8_t is_first=1;
	char sep[]=",";
	
	char rx_buffer[128];
	char addr_str[128];
	//char tmp[50];
	int addr_family;
	int ip_protocol;
	
	struct timeval timeout={2,0}; //set timeout for 2 seconds

	struct sockaddr_in dest_addr;
	dest_addr.sin_addr.s_addr = htonl(INADDR_ANY);
	dest_addr.sin_family = AF_INET;
	dest_addr.sin_port = htons(PORT_SERVER);
	addr_family = AF_INET;
	ip_protocol = IPPROTO_IP;
	inet_ntoa_r(dest_addr.sin_addr, addr_str, sizeof(addr_str) - 1);

	int sock = socket(addr_family, SOCK_DGRAM, ip_protocol);
	if (sock < 0) 
	{
		ESP_LOGE(TAGSERVER, "Unable to create socket: errno %d", errno);
	}
	else
	{	
		ESP_LOGI(TAGSERVER, "Socket created");

		int err = bind(sock, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
		if (err < 0) 
		{
			ESP_LOGE(TAGSERVER, "Socket unable to bind: errno %d", errno);
		}
		else
		{		
			ESP_LOGI(TAGSERVER, "Socket bound, port %d", PORT_SERVER);
		
			setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,sizeof(struct timeval));
			
			if(udp_client_receive()==ESP_OK)
			{
				while (1) 
				{
					ESP_LOGI(TAGSERVER, "Waiting for data");
					struct sockaddr_in6 source_addr; // Large enough for both IPv4 or IPv6
					socklen_t socklen = sizeof(source_addr);

					int len = recvfrom(sock, rx_buffer, sizeof(rx_buffer) - 1, 0, (struct sockaddr *)&source_addr, &socklen);

					// Error occurred during receiving
					if (len < 0) {
						ESP_LOGE(TAGSERVER, "recvfrom failed: errno %d", errno);
						break;
					}
					// Data received
					else 
					{
						// Get the sender's ip address as string
						if (source_addr.sin6_family == PF_INET) 
						{
							inet_ntoa_r(((struct sockaddr_in *)&source_addr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
						} 
						else if (source_addr.sin6_family == PF_INET6) 
						{
							inet6_ntoa_r(source_addr.sin6_addr, addr_str, sizeof(addr_str) - 1);
						}

						rx_buffer[len] = 0; // Null-terminate whatever we received and treat like a string...
						ESP_LOGI(TAGSERVER, "Received %d bytes from %s:", len, addr_str);
						ESP_LOGI(TAGSERVER, "%s", rx_buffer);
	
						if(strncmp(rx_buffer,"name=",5)==0 && strlen(rx_buffer)<=25)
						{
							l_free=max_scandata_len-(30+len+strlen(addr_str)+strlen(scandata)+1);
					
							ESP_LOGI(TAGSERVER, "Free scanbuffer: %d of %d ",l_free, max_scandata_len);
					
							if(l_free<=0)
							{
								ESP_LOGE(TAGSERVER, "Can't add aditionnal data, scanbuffer is full");
								break;
							}
						}
						else
						{
							ESP_LOGE(TAGSERVER, "Invalid data returned");
						}

						if(is_first==0) strcat(scandata,sep);
						sprintf(scandata+strlen(scandata),"{\"name\":\"%s\",\"ip\":\"%s\"}",&rx_buffer[5],addr_str);
						is_first=0;

						int err = sendto(sock, rx_buffer, len, 0, (struct sockaddr *)&source_addr, sizeof(source_addr));
						if (err < 0) 
						{
							ESP_LOGE(TAGSERVER, "Error occurred during sending: errno %d", errno);
							break;
						}
					}
				}
				
				ESP_LOGI(TAGSERVER, "Shutting down socket.");
			}
			else
			{
				ESP_LOGE(TAGSERVER, "Shutting down socket cause client errors");
			}	
		}
	}
	
	shutdown(sock, 0);
	close(sock);
}
Thank you for help.

eliott
Posts: 18
Joined: Sat Mar 28, 2020 11:57 am

Re: Problems with sockets and HTTP server

Postby eliott » Tue Jan 26, 2021 9:58 pm

Hello again,

I took back the exemple of udp_client and coded my function with a bind() to allocate source port. This way I don't have to create a udp client/server I only use an udp client with the good source port I'm compatible with my devices who expect data on specific port.

I really don't hunderstand the link with RTOS task and sockets:

If I start a task, open, use data in/out and close a socket, I can execute my function many times.

If I start a task, open, use data in/out and close a socket, close the task, then open again the task I get errno 118.

Maybe it's a init problem, but I initialised all my data to "0" includes structures...

Please find my simplified code to expose the problem:

This code working, without closing the task:

Code: Select all

static void udp_client_task(void *pvParameters)
{
	//vars init

	while(1)
	{
		//function call
		int sock = socket()		//open socket

		if (sock < 0) { ESP_LOGE(TAG, "Unable to create socket: errno %d", errno); break; }
				
		ESP_LOGI(TAG, "Socket created, sending to %s:%d", HOST_IP_ADRESS, PORT_TO);

		while (1)
		{
			int err = sendto() //send data
			
			if (err < 0) { ESP_LOGE(TAG, "Error occurred during sending: errno %d", errno); break; }
			ESP_LOGI(TAG, "Message sent");
			
			len=recvfrom() 

			if (len < 0) 
			{
				ESP_LOGE(TAG, "recvfrom failed: errno %d", errno);
				break;//stop the task
			}
			else 
			{
				ESP_LOGI(TAG, "Received %d bytes from %s:", len, addr_str);				
			}
		}

		if (sock != -1) {
			ESP_LOGE(TAG, "Sock == %d. Shutting down socket and restarting...",sock);
			shutdown(sock, 2);
			close(sock);
		}
		//IF I CLOSE THE TASK HERE WITH vTaskDelete(NULL); AND RESTART IT by calling "init_udp()", I CAN'T SEND ANYMORE UDP DATA
		//IS THAT BECAUSE THE OLD AND NEX TASK HAS THE SAME NAME ?
		
	}
	vTaskDelete(NULL);	
}

void init_udp()
{
	xTaskCreate(udp_client_task, "udp_client", 4096, NULL, 5, NULL);
}
LOG working code:

Code: Select all

I (455404) [UDP CLIENT]: Socket created, sending to 192.168.1.255:1900
I (456664) [HTTPD GET]: File name: /devicescan
I (456664) [HTTPD GET]: Send 16 bytes (UDP /NOTIFY-V5
) to app_udp_send
I (457404) [UDP CLIENT]: Message sent
I (457684) [UDP CLIENT]: Received 10 bytes from 192.168.1.221:
I (457684) [UDP CLIENT]: UDP /221

I (457684) [UDP CLIENT]: Received 10 bytes from 192.168.1.193:
I (457694) [UDP CLIENT]: UDP /193

I (457694) [UDP CLIENT]: Received 10 bytes from 192.168.1.208:
I (457704) [UDP CLIENT]: UDP /208

E (459704) [UDP CLIENT]: recvfrom failed: errno 11
E (459704) [UDP CLIENT]: Sock == 58. Shutting down socket and restarting...
I (459704) [UDP CLIENT]: Socket created, sending to 192.168.1.255:1900
I (460144) [HTTPD GET]: File name: /devicescan
I (460144) [HTTPD GET]: Send 16 bytes (UDP /NOTIFY-V5
) to app_udp_send
I (461704) [UDP CLIENT]: Message sent
I (461984) [UDP CLIENT]: Received 10 bytes from 192.168.1.221:
I (461984) [UDP CLIENT]: UDP /221

I (461984) [UDP CLIENT]: Received 10 bytes from 192.168.1.193:
I (461994) [UDP CLIENT]: UDP /193

E (463994) [UDP CLIENT]: recvfrom failed: errno 11
E (463994) [UDP CLIENT]: Sock == 58. Shutting down socket and restarting...
I (463994) [UDP CLIENT]: Socket created, sending to 192.168.1.255:1900
I (465064) [HTTPD GET]: File name: /devicescan
I (465064) [HTTPD GET]: Send 16 bytes (UDP /NOTIFY-V5
) to app_udp_send
I (465994) [UDP CLIENT]: Message sent
I (466284) [UDP CLIENT]: Received 10 bytes from 192.168.1.193:
I (466284) [UDP CLIENT]: UDP /193

I (466294) [UDP CLIENT]: Received 10 bytes from 192.168.1.208:
I (466294) [UDP CLIENT]: UDP /208

I (466294) [UDP CLIENT]: Received 10 bytes from 192.168.1.221:
I (466304) [UDP CLIENT]: UDP /221

E (468304) [UDP CLIENT]: recvfrom failed: errno 11
E (468304) [UDP CLIENT]: Sock == 58. Shutting down socket and restarting...
I (468304) [UDP CLIENT]: Socket created, sending to 192.168.1.255:1900
I (469574) [HTTPD GET]: File name: /devicescan
I (469574) [HTTPD GET]: Send 16 bytes (UDP /NOTIFY-V5
) to app_udp_send
I (470304) [UDP CLIENT]: Message sent
I (470584) [UDP CLIENT]: Received 10 bytes from 192.168.1.221:
I (470584) [UDP CLIENT]: UDP /221

I (470584) [UDP CLIENT]: Received 10 bytes from 192.168.1.193:
I (470594) [UDP CLIENT]: UDP /193

I (470594) [UDP CLIENT]: Received 10 bytes from 192.168.1.208:
I (470604) [UDP CLIENT]: UDP /208

E (472604) [UDP CLIENT]: recvfrom failed: errno 11
E (472604) [UDP CLIENT]: Sock == 58. Shutting down socket and restarting...
I (472604) [UDP CLIENT]: Socket created, sending to 192.168.1.255:1900
LOG not working code:

Code: Select all

I (1764) [WIFI]: got ip:192.168.1.244
I (1764) [WIFI]: connect to the AP success
I (1764) [TIME]: Timezone loaded from NVS: -1
I (1764) [TIME]: Timezone set to UTC-1
I (1774) tcpip_adapter: sta ip: 192.168.1.244, mask: 255.255.255.0, gw: 192.168.1.254
I (8734) [HTTPD GET]: File name: /createtask
I (8734) [UDP CLIENT]: Network is 192.168.1.255
I (8744) [UDP CLIENT]: Socket created, sending to 192.168.1.255:1900
I (11994) [HTTPD GET]: File name: /devicescan
I (11994) [HTTPD GET]: Send 16 bytes (UDP /NOTIFY-V5
) to app_udp_send
I (12744) [UDP CLIENT]: Message sent
I (13014) [UDP CLIENT]: Received 10 bytes from 192.168.1.221:
I (13014) [UDP CLIENT]: UDP /221

I (13024) [UDP CLIENT]: Received 10 bytes from 192.168.1.208:
I (13024) [UDP CLIENT]: UDP /208

I (13024) [UDP CLIENT]: Received 10 bytes from 192.168.1.193:
I (13034) [UDP CLIENT]: UDP /193

E (15034) [UDP CLIENT]: recvfrom failed: errno 11
E (15034) [UDP CLIENT]: Sock == 59. Shutting down socket and restarting...
I (27974) [HTTPD GET]: File name: /createtask
I (27974) [UDP CLIENT]: Network is 192.168.1.255
I (27974) [UDP CLIENT]: Socket created, sending to 192.168.1.255:1900
I (30834) [HTTPD GET]: File name: /devicescan
I (30834) [HTTPD GET]: Send 16 bytes (UDP /NOTIFY-V5
) to app_udp_send
E (31974) [UDP CLIENT]: Error occurred during sending: errno 118
E (31974) [UDP CLIENT]: Sock == 59. Shutting down socket and restarting...
Thank you for help.

ESP_Sprite
Posts: 9582
Joined: Thu Nov 26, 2015 4:08 am

Re: Problems with sockets and HTTP server

Postby ESP_Sprite » Wed Jan 27, 2021 12:40 am

Can you post your *actual* code instead, if possible whittled down to something as small as possible that still exhibits the issue? What you posted unfortunately is simplified to the point of uselessness.

eliott
Posts: 18
Joined: Sat Mar 28, 2020 11:57 am

Re: Problems with sockets and HTTP server

Postby eliott » Thu Jan 28, 2021 11:12 pm

Hello,

this is my full code *blocking code* with no sys task, unable to run twice cause errno 23;

Code: Select all

 (6771) [HTTPD GET]: File name: /images/NavCron.png
I (6791) [HTTPD GET]: File name: /wifistatus
I (8461) [HTTPD GET]: File name: /devicelist
I (8471) [HTTPD GET]: File name: /devicescan
I (8471) [UDP CLIENT]: Network is 192.168.1.255
I (8471) [UDP CLIENT]: Socket created, sending to 192.168.1.255:2000
I (8481) [UDP CLIENT]: Message sent
I (8861) [UDP CLIENT]: Received 11 bytes from 192.168.1.183:
I (8861) [UDP CLIENT]: name=Bureau
I (8871) [UDP CLIENT]: Free scanbuffer: 700 of 768
E (10871) [UDP CLIENT]: recvfrom failed: errno 11
E (10871) [UDP CLIENT]: Sock == 63. Shutting down socket and restarting...
I (15631) [HTTPD GET]: File name: /devicescan
I (15631) [UDP CLIENT]: Network is 192.168.1.255
I (15631) [UDP CLIENT]: Socket created, sending to 192.168.1.255:2000
E (15631) [UDP CLIENT]: Error occurred during sending: errno 118
I (15651) [HTTPD GET]: File name: /devicelist
I (19111) [HTTPD GET]: File name: /devicescan
I (19111) [UDP CLIENT]: Network is 192.168.1.255
E (19111) [UDP CLIENT]: Unable to create socket: errno 23
I (19121) [HTTPD GET]: File name: /devicelist
I (21571) [HTTPD GET]: File name: /devicescan
I (21571) [UDP CLIENT]: Network is 192.168.1.255
E (21571) [UDP CLIENT]: Unable to create socket: errno 23
I (21581) [HTTPD GET]: File name: /devicelist
I (23821) [HTTPD GET]: File name: /images/IconLoader.gif
I (23841) [HTTPD GET]: File name: /devicescan
I (23841) [UDP CLIENT]: Network is 192.168.1.255
E (23841) [UDP CLIENT]: Unable to create socket: errno 23
I (23851) [HTTPD GET]: File name: /devicelist

Code: Select all

#define PORT_TO 2000
#define PORT_FROM 2000

static const char *TAG = "[UDP CLIENT]";

esp_err_t app_udp_send(char * payload, size_t len, char * scandata, uint16_t max_scandata_len)
{
	char rx_buffer[128]={0};
	char addr_str[128]={0};
	int addr_family=0;
	int ip_protocol=0;
	struct timeval timeout={2,0}; //set timeout for 2 seconds
	char *HOST_IP_ADRESS;

	uint8_t is_first=1;
	int32_t l_free;
	char sep[]=",";
	
	HOST_IP_ADRESS=get_sta_ip();
	uint8_t i;
		
	for(i=strlen(HOST_IP_ADRESS); i>5; i--)
	{
		if(*(HOST_IP_ADRESS+i)=='.') break;
	}
		
	if(i==5)
	{
		ESP_LOGI(TAG, "Can't match network with IP %s",HOST_IP_ADRESS);
		return ESP_FAIL;
	}
	else
	{
		//set source port

		struct sockaddr_in from_addr;
		memset(&from_addr, 0, sizeof(from_addr));
		from_addr.sin_addr.s_addr = inet_addr(HOST_IP_ADRESS);
		from_addr.sin_family = AF_INET;
		from_addr.sin_port = htons(PORT_FROM);

		memcpy((HOST_IP_ADRESS+i+1),"255\0",4);
		ESP_LOGI(TAG, "Network is %s",HOST_IP_ADRESS);
			
		struct sockaddr_in dest_addr;
		memset(&dest_addr, 0, sizeof(dest_addr));
		dest_addr.sin_addr.s_addr = inet_addr(HOST_IP_ADRESS);
		dest_addr.sin_family = AF_INET;
		dest_addr.sin_port = htons(PORT_TO);
		addr_family = AF_INET;
		ip_protocol = IPPROTO_IP;
		inet_ntoa_r(dest_addr.sin_addr, addr_str, sizeof(addr_str) - 1);

		int sock = socket(addr_family, SOCK_DGRAM, ip_protocol);
				
		if (sock < 0)
		{
			ESP_LOGE(TAG, "Unable to create socket: errno %d", errno);
			return ESP_FAIL;
		}
				
		bind(sock, (struct sockaddr *)&from_addr, sizeof(struct sockaddr)); //set source port
		setsockopt(sock,SOL_SOCKET,SO_RCVTIMEO,(char*)&timeout,sizeof(struct timeval)); //set timeout 2 secs
				
		ESP_LOGI(TAG, "Socket created, sending to %s:%d", HOST_IP_ADRESS, PORT_TO);
		
		int err = sendto(sock, payload, strlen(payload), 0, (struct sockaddr *)&dest_addr, sizeof(dest_addr));
		if (err < 0)
		{
			ESP_LOGE(TAG, "Error occurred during sending: errno %d", errno);
			return ESP_FAIL;
		}
		ESP_LOGI(TAG, "Message sent");

		while (1)
		{
			struct sockaddr_in source_addr; // Large enough for both IPv4 or IPv6
			socklen_t socklen = sizeof(source_addr);
			int len = recvfrom(sock, rx_buffer, sizeof(rx_buffer) - 1, 0, (struct sockaddr *)&source_addr, &socklen);

			// Error occurred during receiving
			if (len < 0) 
			{
				ESP_LOGE(TAG, "recvfrom failed: errno %d", errno);
				break;//stop the task
			}
			// Data received
			else
			{
				// Get the sender's ip address as string
				if (source_addr.sin_family == PF_INET)
				{
					inet_ntoa_r(((struct sockaddr_in *)&source_addr)->sin_addr.s_addr, addr_str, sizeof(addr_str) - 1);
				}
				else if (source_addr.sin_family == PF_INET6)
				{
					inet6_ntoa_r(source_addr.sin_addr, addr_str, sizeof(addr_str) - 1);
				}
							
				rx_buffer[len] = 0; // Null-terminate whatever we received and treat like a string...
				ESP_LOGI(TAG, "Received %d bytes from %s:", len, addr_str);
				ESP_LOGI(TAG, "%s", rx_buffer);
							
				if(strncmp(rx_buffer,"name=",5)==0 && strlen(rx_buffer)<=25)
				{
					l_free=max_scandata_len-(30+len+strlen(addr_str)+strlen(scandata)+1);
								
					ESP_LOGI(TAG, "Free scanbuffer: %d of %d ",l_free, max_scandata_len);
								
					if(l_free<=0)
					{
						ESP_LOGE(TAG, "Can't add aditionnal data, scanbuffer is full");
						break;
					}
								
					if(is_first==0) strcat(scandata,sep);
					sprintf(scandata+strlen(scandata),"{\"name\":\"%s\",\"ip\":\"%s\"}",&rx_buffer[5],addr_str);
					is_first=0;
				}
				else
				{
					ESP_LOGE(TAG, "Invalid data returned");
				}
			}
		}

		if (sock != -1) 
		{
			ESP_LOGE(TAG, "Sock == %d. Shutting down socket and restarting...",sock);
			shutdown(sock, 2);
			close(sock);
		}
					
		if(errno!=11)
		{
			return ESP_FAIL;
		}
		else
		{
			return ESP_OK;			
		}
	}
}
Thank you.

ESP_Sprite
Posts: 9582
Joined: Thu Nov 26, 2015 4:08 am

Re: Problems with sockets and HTTP server

Postby ESP_Sprite » Fri Jan 29, 2021 6:48 am

That still is not something where 1. I can look at how you start up and kill your tasks, or 2. that I can put in an ESP32 here to try and replicate the issue.

eliott
Posts: 18
Joined: Sat Mar 28, 2020 11:57 am

Re: Problems with sockets and HTTP server

Postby eliott » Fri Jan 29, 2021 7:17 pm

Hello,

I changed my code with minimum function for udp_app. Working with call function in main.

I put my previous code, working now, I really don't hunderstand the difference, certainly a full clean helped.

I noticed that my bind is working once, after sending from "PORT_FROM" = 2100 the port is incremented: 60226,20227,62228 etc...

Maybe it was the source of the problem ?

Code: Select all

		//set source port
		struct sockaddr_in from_addr;
		memset(&from_addr, 0, sizeof(from_addr));
		from_addr.sin_addr.s_addr = inet_addr(HOST_IP_ADRESS);
		from_addr.sin_family = AF_INET;
		from_addr.sin_port = htons(PORT_FROM);
		[...]
		bind(sock, (struct sockaddr *)&from_addr, sizeof(struct sockaddr)); //set source port

Who is online

Users browsing this forum: Baidu [Spider], BinaryPoet and 250 guests