sockets

How do I dynamically bind a socket to only one network interface?

Currently I do the following to listen on any available port on all interfaces: // hints struct for the getaddrinfo call struct addrinfo hints, *res; memset(&hints, 0, sizeof hints); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; // Fill in addrinfo with getaddrinfo if (getaddrinfo(NULL, "0", &...

System.Net.Sockets.NetworkStream's Async read callback

I'm may be just misunderstanding something fundamental here but... Senario: I call System.Net.Sockets.NetworkStream's BeginRead method and my machine receives a response/request from a network device. The runtime runs my callback in its own thread. Before this thread can call EndRead, the machine receives another response/request. Ques...

How do you address data returned to a socket in python?

Say you are telneting into IRC to figure out how it all works. As you issue commands the IRC server returns data telling you what it's doing. Once I have created a default script that basically is how a normal IRC connection between server and client occurs, if it ever deviates from that it won't tell me what is wrong. I need to be ab...

Improve a IRC Client in Python

Hello, How i can make some improvement in my IRC client made in Python. The improvement is: How i can put something that the user can type the HOST, PORT, NICK, INDENT and REALNAME strings and the message? And here is the code of the program: simplebot.py import sys import socket import string HOST="irc.freenode.net" PORT=6667 NIC...

Socket? python -m SimpleHTTPServer

Problem: to get the command working here. My domain is http://cs.edu.com/user/share_dir, but I cannot get the command working by typing it to a browser: http://cs.edu.com/user/share_dir:8000 Question: How can I get the command working? ...

Can a sequence of json objects be unequivocally parsed without further delimiters or knowing their length?

I am planning a protocol where two applications open a socket between them and send and receive legal json objects. Can a sequence of json objects be unequivocally parsed, or will I need delimiters, or prefixing each object with its lengths or something like that? ...

How do I get IP address from socket In Windows

I have the DWORD socket in windows. I need to know if it is a connection that goes out to the internet or if it is a local connection, to some form of localhost. Is there a good way to get the address that the socket is connected to in windows from just the socket? Or is there a better way to tell if the connection is local or not? ...

Download a URL in C++

I want to be able to download a URL in C++. Something as simple as: std::string s; s=download("http://www.example.com/myfile.html"); Ideally, this would include URLs like: ftp://example.com/myfile.dat file:///usr/home/myfile.dat https://example.com/myfile.html I was using asio in Boost, but it didn't really seem to have the cod...

Sockets: How to send data to the client without 'waiting' on them as they receive/parse it

I have a socket server, written in C++ using boost::asio, and I'm sending data to a client. The server sends the data out in chunks, and the client parses each chunk as it receives it. Both are pretty much single threaded right now. What design should I use on the server to ensure that the server is just writing out the data as fast...

How do I receive SNMP traps on OS X?

I need to receive and parse some SNMP traps (messages) and I would appreciate any advice on getting the code I have working on my OS X machine. I have been given some Java code that runs on Windows with net-snmp. I'd like to either get the Java code running on my development machine or whip up some Python code to do the same. I was able...

Adobe Socket Policy File Server Problems

Has anyone been able to successfully implement a service to serve the required socket policy file to FlashPlayer? I am running the Python implementation of the service provided by Adobe at http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html and using the following policy file: <?xml version="1.0" encoding="UTF...

Is there a way to set TCP options using the sockets API?

I am relatively new to socket programming so this may sound like a very lame question. I have to use authenticated TCP(MD5 as a TCP option to start with) as a transport for some application. I was wondering if this could be done using the sockets API or there is some other form of an existing TCP APIs that I could use to do the same. I w...

HTTPS with Linux sockets?

I need to send an HTTP request to a server using HTTPS on Linux using plain sockets. Is there a way to do this? Code is appreciated. Thanks ...

Running Async IO threads to completion in same order as received

Sorry, I am very new to all this multithreading stuff... I'm working on a client/server app and I'm going to use System.Net.Sockets.NetworkStream's Async IO methods. I'm aware that after calling BeginRead, the system will start calling my callback every time it receives data. The callback could take a significant amount of time to co...

Is there a way to get non-locking stream insertion/extraction on basic_iostream in Windows?

I'm a C++ developer who has primarily programmed on Solaris and Linux until recently, when I was forced to create an application targeted to Windows. I've been using a communication design based on C++ I/O stream backed by TCP socket. The design is based on a single thread reading continuously from the stream (most of the time blocked i...

Connection refused when trying to open, write and close a socket a few times (Python)

I have a program that listens on a port waiting for a small amount of data to tell it what to do. I run 5 instances of that program, one on each port from 5000 to 5004 inclusively. I have a second program written in Python that creates a socket "s", writes the data to port 5000, then closes. It then increments the port number and create...

Maintaining .NET Asynchronous Socket Connections in a Server Push application

Hi! I've implemented a solution that uses asynchronous sockets to push information from a server to all connected Silverlight clients. I'm having a few problems with the Push Server and need some clarification since this is the first time I'm working with Sockets and in an fully asynchronous environment. Right now the Push Server acc...

What is the second paramenter of TCPSocket.send in Ruby?

I am using this line to send a message via a Ruby (1.8.7) socket: @@socket.send login_message, 0 (This works fine) What is the second parameter for? I can't find the send method in the Ruby API docs... I first thought that it was some C style length of the message. This is why I used login_message.length as second parameter. That wo...

Ruby TCPSocket write doesn't work, but puts does?

I'm working on a Ruby TCP client/server app using GServer and TCPSocket. I've run into a problem that I don't understand. My TCPSocket client successfully connects to my GServer, but I can only send data using puts. Calls to TCPSocket.send or TCPSocket.write do nothing. Is there some magic that I'm missing? tcp_client = TCPSocket.ne...

Java NIO Threading issue with SocketChannel.write()

Sometimes, while sending a large amount of data via SocketChannel.write(), the underlying TCP buffer gets filled up, and I have to continually re-try the write() until the data is all sent. So, I might have something like this: public void send(ByteBuffer bb, SocketChannel sc){ sc.write(bb); while (bb.remaining()>0){ Thread...