asyncsocket

Fast Repeat TakeWhile causes infinite loop

假如想象 提交于 2019-12-04 04:03:05
How can I make the following observable repeat until stream.DataAvailable is false? Currently it looks like it never stops. AsyncReadChunk and Observable.Return inside the Defer section make OnNext call then OnCompleted call. When Repeat receives the OnNext call it passes it to TakeWhile. When TakeWhile's is not satisfied it completes the observable but I think the OnCompleted that comes right after the OnNext is so fast that it makes Repeat to re-subscribes to the observable and causes the infinite loop. How can I correct this behaviour? public static IObservable<byte[]> AsyncRead(this

python asyncio run event loop once?

99封情书 提交于 2019-12-04 03:30:05
I am trying to understand the asyncio library, specifically with using sockets. I have written some code in an attempt to gain understanding, I wanted to run a sender and a receiver sockets asynchrounously. I got to the point where I get all data sent up till the last one, but then I have to run one more loop. Looking at how to do this, I found this link from stackoverflow , which I implemented below -- but what is going on here? Is there a better/more sane way to do this than to call stop followed by run_forever ? The documentation for stop() in the event loop is: Stop running the event loop.

why is time rising for more than one request to asyncio server in python?

本小妞迷上赌 提交于 2019-12-01 18:55:05
I wrote a pythonic server with socket. that should receives requests at the same time(parallel) and respond them parallel. When i send more than one request to it, the time of answering increase more than i expected. server: import datetime import asyncio, timeit import json, traceback from asyncio import get_event_loop requestslist = [] loop = asyncio.get_event_loop() async def handleData(reader, writer): message = '' clientip = '' data = bytearray() print("Async HandleData", datetime.datetime.utcnow()) try: start = timeit.default_timer() data = await reader.readuntil(separator=b'\r\n\r\n')

Must call EndRead() in ALL cases?

瘦欲@ 提交于 2019-12-01 17:02:23
问题 Related to asynchronous IO using a (bidirectional) NetworkStream, MSDN says that "EndRead must be called once for every call to BeginRead." Is this true even for cases where the EndRead() will throw an exception, such as in the case that the NetworkStream has been closed after the BeginRead() has been issued? I don't want the overhead of the throwing of the exception, but neither do I want to leak OS precious resources reserved by BeginRead(). I also know that the stream could be closed

Enable non-blocking socket

三世轮回 提交于 2019-12-01 13:27:24
问题 I have a server written in C/C++. I set the wrapper for the connection as follow: //START WRAPPER void Server::init_address(int port) { memset(&(this->serv_addr), 0, sizeof(this->serv_addr)); this->serv_addr.sin_family = AF_INET; this->serv_addr.sin_port = htons(port); this->serv_addr.sin_addr.s_addr = htonl(INADDR_ANY); } int Server::w_socket() { int retv; retv = socket(PF_INET, SOCK_STREAM, 0); //FIXME //fcntl(retv, F_SETFL, O_NONBLOCK); if(retv == -1) { std::string err_msg(strerror(errno))

Unable to read data correctly from .Net socket in C#

两盒软妹~` 提交于 2019-12-01 13:15:57
问题 I have a client and server class in C# that uses socket communication. The Server looks like this: public class AsyncTcpServer { private Socket _server_socket; private Socket _client_socket; private byte[] _receive_buffer; private byte[] _send_buffer; private NetworkStream _ns; public void Start() { try { _server_socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); _server_socket.Bind(new IPEndPoint(IPAddress.Any, 17999)); _server_socket.Listen(0); _server

GCDAsyncUdpSocket immediately closes when sending to an IPv6 address

萝らか妹 提交于 2019-12-01 06:04:56
问题 I'm connecting via UDP to a server on a different device which is advertised by Bonjour. When both the iOS device which this code is running on, and the server, are on our wifi network it works just fine because the bonjour service resolves to a 192.168.0.xxx address which our dhcp server hands out. However when it is advertised by bluetooth, sometimes the service resolves to 169.254.xxx.xxx (IPv4) in which case it works just fine. But sometimes it resolves to fe80::xxxx:xxxx:xxxx:xxxx (IPv6)

.NET question about asynchronous socket operations and message framing

China☆狼群 提交于 2019-11-30 23:55:04
问题 I've been looking everywhere for examples on how to deal with TCP message framing. I see many examples where NetworkStreams are passed into a StreamReader or StreamWriter object and then use ReadLine or WriteLine methods for '\n' delimited messages. My application protocol contains messages ending in '\n' so the NetworkStream seems to be the way to go. However, I can't find any specific examples on the proper way to handle all of this in combination with asynchronous sockets. When

AsyncUdpSocket how to use receive

孤街浪徒 提交于 2019-11-30 02:40:21
问题 I am trying to get a program for iPhone running on the simulator. My problem is with receiving UDP data. I use asyncUdpSocket. If I make a socket and use sendData:(NSData) toHost: ,... well it works fine. The think i can just not figure out is how the receive functions works. I assume something like this: socket = [[AsyncUdpSocket alloc] initWithDelegate:self]; [socket bindToPort:8000] error:nil] //returns YES [socket receiveWithTimeout:-1 tag:1]; I believe it should then call the method -

Ice cast source client for ios

本秂侑毒 提交于 2019-11-29 23:47:32
问题 I have been trying to create a source client for ice cast for ios. I have been able to connect using asyncsocket to connect to the socket. I am also able to write data to the server. The icecast configuration is done for mp3 format. But the mp3 file written to the server is corrupt. I am providing some code snippets. Header: NSString *string = @"SOURCE /sync HTTP/1.0\r\n" "Authorization: Basic c291cmNlOmhhY2ttZQ==\r\n" "User-Agent: butt-0.1.12\r\n" "User-Agent: butt-0.1.12\r\n" "content-type: