sockets

How to bind to all addresses of only one network interface (Linux)?

限于喜欢 提交于 2021-01-29 03:52:59
问题 What I am trying to achieve is binding an IPv6 socket to any address of just one particular device , not system-wide. My intuition is that I could setsockopt() with SO_BINDTODEVICE followed by a bind to :: . It mostly does what I expect it to do. The behaviour is the same in v4. The sockets bound to an interface with SO_BINDTODEVICE will only accept connections made to addresses on that interface. That much is expected. However, I run into errno "Address already in use", if I'm trying to bind

Behavior of writing to TCP socket before reading all data

∥☆過路亽.° 提交于 2021-01-29 03:24:55
问题 I've been writing small specific purpose HTTP servers for some applications of mine, and I noticed that, if you write() before you read() all available data, the bytes are not sent properly. For example, after read() ing only the request line ( GET / HTTP/1.1\r\n ) sent by my browser, I write() : HTTP/1.1 200 OK\r\n Connection: close\r\r Content-Type: text/html\r\n \r\n (some HTML stuff) Wireshark capture of this write() : '\n' bytes and Content-Type header are gone! (Wireshark always

QBluetoothSocketPrivate::_q_readNotify() 14 error

戏子无情 提交于 2021-01-29 03:00:34
问题 i write an simple application to access the PBAP of my smartphone from my pc (Linux, Debian). I see all services of my smartphone, i can also connect (the smartphone gets a pairing request). But after a few seconds i get the following error: qt.bluetooth.bluez: void QBluetoothSocketPrivate::_q_readNotify() 14 error: -1 "Die Ressource ist zur Zeit nicht verfügbar" Has anybody an idea how to fix it? This is the function i call: void ServiceDiscoveryDialog::startClient(const

Why in asio's example the tcp acceptor pattern uses shared_pointer model wrapping heap socket, while udp use stack socket?

大兔子大兔子 提交于 2021-01-28 20:50:50
问题 Source code: https://think-async.com/Asio/asio-1.18.0/doc/asio/tutorial/tutdaytime7/src.html tcp_server shows an intention to use socket on the heap, wrapped by a type called tcp_connection. class tcp_server { private: void start_accept() { tcp_connection::pointer new_connection = tcp_connection::create(io_context_); acceptor_.async_accept(new_connection->socket(), boost::bind(&tcp_server::handle_accept, this, new_connection, asio::placeholders::error)); } void handle_accept(tcp_connection:

Confusion about syn queue and accept queue

断了今生、忘了曾经 提交于 2021-01-28 20:04:40
问题 When reading TCP source code, I find a confused thing: I know TCP has two queues in 3 way handshake: The first queue stores connections which server has received the SYN and send back ACK + SYN , which we call as syn queue . The second queue stores the connections that 3WHS are successful and connection established, which we call as accept queue . But when reading codes, I find listen() will call inet_csk_listen_start() , which will call reqsk_queue_alloc() to create icsk_accept_queue . And

Sails WebSocket connection to 'ws:

て烟熏妆下的殇ゞ 提交于 2021-01-28 19:14:39
问题 I try to run server sails in production via command: sails lift --prod then I have error: VM448 production.min.js:1 WebSocket connection to 'ws://localhost:1337/socket.io/?__sails_io_sdk_version=1.2.1&__sails_io_sdk_platform=browser&__sails_io_sdk_language=javascript&EIO=3&transport=websocket' failed: Error during WebSocket handshake: Unexpected response code: 400 When I run server in development environment via: sails lift that works well. How can I fix this problem? 回答1: For fix this

How to write an .exe file using C# code with StreamWriter?

六眼飞鱼酱① 提交于 2021-01-28 18:44:51
问题 Actually I am copying an exe file over sockets. I am able to copy a text using StreamWriter Class but i used the same code for copying a exe file , it created a exe file with the desired name but I cannot run it. "This app cannot run on your PC". I have Windows 8 x64, that is irrelevant. static void Main(string[] args) { TcpClient tcpclient = new TcpClient(); tcpclient.Connect("localhost", 20209); NetworkStream stm = tcpclient.GetStream(); byte[] buffer = new byte[1024]; var fs = File.Open("F

Python TCP server socket

佐手、 提交于 2021-01-28 14:58:16
问题 I'm trying to open server socket using python the code that I'm using wait for connection and pause the loop until the next connection achieved when its trying to execute this line >> connection, client_address = sock.accept() but I don't need to pause the loop Is there any method to make the code skip this line and continue the loop if there is no connection code : Server import socket import sys # Create a TCP/IP socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) # Bind the

Read only desired amount of bytes using Boost.Asio

巧了我就是萌 提交于 2021-01-28 14:26:51
问题 I'm just creating a very simple C++ class that provides me a few methods, like connect() and read() , instead of exposing all the Boost.Asio socket calls. Right now, I'm trying to find out how to create a method that reads only the desired amount of bytes: SocketClient::read(int bytes, char* data); //reads desired amount of bytes and puts them in data, size of data>bytes! Unfortunately, I found no read_byte function in Boost.Asio. I do not want to drop bytes that have been received, but not

Using unsigned char instead of char because of its range

怎甘沉沦 提交于 2021-01-28 12:14:04
问题 I've been working on a small pure C client application (my first :/) which uses TCP socket for communication with the server. The Server sends me a packet (C structure) in which the first byte contains the size of the packet. The problem is that server is using unsigned char to represent the size of the packet because char is signed (from -128 to +127) and +127 is not enough to represent size that can be up to 255 in some packets. => I need a unsigned char buffer; In Linux, the second