network-programming

c++ - Boost ASIO networking server/client

大兔子大兔子 提交于 2020-01-01 06:44:10
问题 I have written a program for client and server. The program currently does the following: Server listens to an end point for a connection Client connects to the server server sends message on accepting a connection client receives the message I'm doing this asynchronously. But, the problem is they can only send/receive one message. After that, they just terminate. Below is my code: #include <iostream> #include <vector> #include<boost/asio.hpp> std::vector<char> buff(256); void SendHandler

Is new socket created for every request?

筅森魡賤 提交于 2020-01-01 05:32:09
问题 I am trying to wrap my head around network sockets. So far my understanding is that a server creates a new socket that is bound to the specific port. Then it listens to this socket to deal with client requests. I've read this tutorial http://docs.oracle.com/javase/tutorial/networking/sockets/definition.html and it says If everything goes well, the server accepts the connection. Upon acceptance, the server gets a new socket bound to the same local port and also has its remote endpoint set to

Spark cluster Master IP address not binding to floating IP

Deadly 提交于 2020-01-01 05:12:07
问题 I'm trying to configure a Spark cluster using OpenStack. Currently I have two servers named spark-master (IP: 192.x.x.1, floating IP: 87.x.x.1) spark-slave-1 (IP: 192.x.x.2, floating IP: 87.x.x.2) I am running into problems when trying to use these floating IPs vs the standard public IPs. On the spark-master machine, the hostname is spark-master and /etc/hosts looks like 127.0.0.1 localhost 127.0.1.1 spark-master The only change made to spark-env.sh is export SPARK_MASTER_IP='192.x.x.1' . If

What are the advantages NAPI before the IRQ Coalesce?

。_饼干妹妹 提交于 2020-01-01 04:54:16
问题 As known there are two approach to avoid some overheads of hardware interrupts in highload networks, when there are too many hardware interrupts, that switching to them takes too much time. It is very important for performance and choosing approach of programm style. NAPI (New API) - Does not use hardware interrupts , and polls the Ethernet-device every certain period of time. The Linux kernel uses the interrupt-driven mode by default and only switches to polling mode when the flow of

Persistent HttpURLConnections on Android

烂漫一生 提交于 2020-01-01 03:49:05
问题 I've got an issue trying to get the Android application (well, Service, it case it makes any difference) to use persistent HTTP 1.1 connections. The following loop (simplified test case) works through a single TCP session on a desktop JRE, but on an Android device results in the whole socket creation/teardown cycle. while (true) { URL url; try { url = new URL("http://10.0.0.125:8080/SRV?"); URLConnection connection = url.openConnection(); HttpURLConnection httpConnection = (HttpURLConnection)

Boost Asio type to use for both unix-socket and tcp socket

ぐ巨炮叔叔 提交于 2020-01-01 03:29:08
问题 We have a boost asio based networking code, which connects to a remote side. The local side could be either a tcp4 socket or a unix socket. Is there a typename to use that could hold both of these type of boost sockets? (e.g. something like a base class for both?). Currently our code use boost::asio::generic::stream_protocol::socket for tcp socket, and boost::asio::local::stream_protocol::socket for a unix socket. 回答1: Actually, there's a dedicated ip::tcp::socket type for tcp sockets. As for

Retrieve PAC script using WPAD on OSX

社会主义新天地 提交于 2020-01-01 00:21:53
问题 How do I retrieve the PAC script using WPAD on OSX? is it enough to fetch the contents of "http://wpad/wpad.dat" in hopes that the DNS has "wpad" pre-configured for this convention? is there a more "formal" method of doing this? 回答1: Here is how to get PAC proxies for a given URL: #import <Foundation/Foundation.h> #import <CoreServices/CoreServices.h> #import <SystemConfiguration/SystemConfiguration.h> CFArrayRef CopyPACProxiesForURL(CFURLRef targetURL, CFErrorRef *error) { CFDictionaryRef

Sending DHCP Discover using python scapy

≡放荡痞女 提交于 2019-12-31 15:50:49
问题 I am new to python and learning some network programming, I wish to send an DHCP Packet through my tap interface to my DHCP server and expecting some response from it. I tried with several packet building techniques such a structs and ctypes and ended up with using scapy. Here I am able to send DHCP Packet but unable to get any response from the DHCP server(Analyzed using wireshark and tcpdump)..My packet looked like same as original DHCP packet but failed to get response. Here is my code

Bandwidth throttling in Python

时光怂恿深爱的人放手 提交于 2019-12-31 08:39:44
问题 What libraries out there let you control the download speed of network requests (http in particular). I don't see anything built-in in urllib2 (nor in (Py)Qt which I intend on using). Can Twisted control bandwidth? If not, how can I control the read buffer size of urllib2 or Twisted? sleep ing to suspend network operations isn't an option. 回答1: Of course twisted can. You want twisted.protocols.policies.ThrottlingFactory. Just wrap your existing factory in it before you pass it to whatever

Does epoll(), do its job in O(1)?

懵懂的女人 提交于 2019-12-31 08:33:04
问题 Wikipedia says unlike the older system calls, which operate at O(n), epoll operates in O(1) [2]). http://en.wikipedia.org/wiki/Epoll However, the source code at fs/eventpoll.c on Linux-2.6.38, seems it is implemented with an RB tree for searching, which has O(logN) /* * Search the file inside the eventpoll tree. The RB tree operations * are protected by the "mtx" mutex, and ep_find() must be called with * "mtx" held. */ static struct epitem *ep_find(struct eventpoll *ep, struct file *file,