sockets

My socket.io server start disconnecting clients randomly (for a “ping timeout” reason) when many clients are connected

Deadly 提交于 2021-02-05 09:28:56
问题 I'm building a website, where my client communicates with the server over web sockets. I'm using nodejs on the backend and hence, the famous socket.io library for web sockets communication. The Problem Everything works fine with 1 to ~ 40 clients, after that the server starts disconnecting clients randomly. at the start I thought it is a scaling problem, maybe memory or something like that. However, after an extensive debugging session, I noticed that the reason for disconnection is ping

Python working with hostnames, hostname to IP

只谈情不闲聊 提交于 2021-02-05 09:28:27
问题 In python I need to get IP from hostname: socket.gethostbyname('www.python.org') # returns ip good socket.gethostbyname('http://python.org') # raises error I need to deal with hostnames starting with 'http://' so I figured out a way to remake them like this: a = 'http://python.org' a.replace('http://', 'www.') print a # Why does it print http://python.org ??? I'm not sure I do the right thing. Plz help me with translating this type of hostname to IP 回答1: You want urlparse : >>> import

Python working with hostnames, hostname to IP

我是研究僧i 提交于 2021-02-05 09:28:10
问题 In python I need to get IP from hostname: socket.gethostbyname('www.python.org') # returns ip good socket.gethostbyname('http://python.org') # raises error I need to deal with hostnames starting with 'http://' so I figured out a way to remake them like this: a = 'http://python.org' a.replace('http://', 'www.') print a # Why does it print http://python.org ??? I'm not sure I do the right thing. Plz help me with translating this type of hostname to IP 回答1: You want urlparse : >>> import

My socket.io server start disconnecting clients randomly (for a “ping timeout” reason) when many clients are connected

拟墨画扇 提交于 2021-02-05 09:28:05
问题 I'm building a website, where my client communicates with the server over web sockets. I'm using nodejs on the backend and hence, the famous socket.io library for web sockets communication. The Problem Everything works fine with 1 to ~ 40 clients, after that the server starts disconnecting clients randomly. at the start I thought it is a scaling problem, maybe memory or something like that. However, after an extensive debugging session, I noticed that the reason for disconnection is ping

Sending CAN frame via UDP in Python

 ̄綄美尐妖づ 提交于 2021-02-05 08:46:07
问题 I made UDP socket connection between two Linux machines and can send for example b"Hello, World!" easily. But now I need to send the below CAN frame from can import Message send_msg = Message(data=[1, 2, 3, 4, 5]) So if I print send_msg it shows: Timestamp: 0.000000 ID: 00000000 X DLC: 5 01 02 03 04 05 I want to get this printed on the receiving end. The sending and receiving end codes I am using are below: Sending: import socket UDP_IP = "10.140.189.249" UDP_PORT = 5005 from can import

recvfrom with Raw Sockets, get just the data

六月ゝ 毕业季﹏ 提交于 2021-02-05 08:11:26
问题 I'm trying to implement my own transport layer protocol, but I'm perfectly happy to leave the network layer as-is and not need to mess with the actual IP header information. But of course, when calling recvfrom() on a raw socket, you are given the raw IP datagram, while the sockaddr struct is not filled in. Is there anyway to coax the stack to fill in those structs and leave the ip header out of the data portion, or does that need to be implemented by hand? Receiver: struct sockaddr_in sender

recvfrom with Raw Sockets, get just the data

心已入冬 提交于 2021-02-05 08:11:08
问题 I'm trying to implement my own transport layer protocol, but I'm perfectly happy to leave the network layer as-is and not need to mess with the actual IP header information. But of course, when calling recvfrom() on a raw socket, you are given the raw IP datagram, while the sockaddr struct is not filled in. Is there anyway to coax the stack to fill in those structs and leave the ip header out of the data portion, or does that need to be implemented by hand? Receiver: struct sockaddr_in sender

nonblocking send()/write() and pending data dealing

北战南征 提交于 2021-02-05 07:19:04
问题 when the send(or write) buffer is going to be full, let me say, only theres is only 500 bytes space. if I have a NONBLOCKING fd, and do n = send(fd, buf, 1000,0) here I wll get n<0, and I can get EWOULDBLOCK or EAGAIN error. my questions are: 1 here, the send write 500 bytes into the send buffer or 0 bytes to the send buffer? 2 if 500 bytes are sent to the buffer and if the fd is a UDP socket, then the datagram is split into 2 parts? 3 I need to use the fd to send many datagrams, if this time

EMSGSIZE when trying to send data on raw IP packet

非 Y 不嫁゛ 提交于 2021-02-05 06:50:26
问题 My code sends a raw IP packet to 12.12.12.12 and fails because of EMSGSIZE . I think that it limits my packet according to Ethernet MTU, but it should send packets <= 65,535 bytes (IPv4 MTU). I've tried to send a packet to 127.0.0.1 and this worked well, but the error occurs when I send a packet to a non-local IP. #include <assert.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <arpa/inet.h> int main(void) { int fd;

EMSGSIZE when trying to send data on raw IP packet

蹲街弑〆低调 提交于 2021-02-05 06:50:12
问题 My code sends a raw IP packet to 12.12.12.12 and fails because of EMSGSIZE . I think that it limits my packet according to Ethernet MTU, but it should send packets <= 65,535 bytes (IPv4 MTU). I've tried to send a packet to 127.0.0.1 and this worked well, but the error occurs when I send a packet to a non-local IP. #include <assert.h> #include <string.h> #include <unistd.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <arpa/inet.h> int main(void) { int fd;