sockets

Python socket accept blocks - prevents app from quitting

I've written a very simple python class which waits for connections on a socket. The intention is to stick this class into an existing app and asyncronously send data to connecting clients. The problem is that when waiting on an socket.accept(), I cannot end my application by pressing ctrl-c. Neither can I detect when my class goes out...

UNIX nonblocking I/O: O_NONBLOCK vs. FIONBIO

In every example and discussion I run across in the context of BSD socket programming, it seems that the recommended way to set a file descriptor to nonblocking I/O mode is using the flag to fcntl(), e.g. int flags = fcntl(fd, F_GETFL, 0); fcntl(fd, F_SETFL, flags | O_NONBLOCK); I've been doing network programming in UNIX for over te...

Winsock2.h include error

Hi Did anyone try to include winsock2.h and then tried to compile it on cygwin? Unfortuantely I get the following error message: winsock2.h:635: error: declaration of C function 'int gethostname(char*, int)' conflicts with /usr/include/sys/unistd.h:2006: error: previous declaration 'int gethostname(char, size t)' here Does anyone know...

Java Socket Testing

I setup a Server on my machine that listens on port 8888 for incoming connections. Now I wanna make absolutely sure that this port is properly working and waiting for incoming connections. Is there maybe a tool I could use for Win XP that tells me if on my local machine there is an TCP port waiting for a connection? ...

C# UDP broadcast client/server does not work

I'm using .NET 2.0 and have created a fairly simple udp broadcast app and udp listener. Listener code: Socket listener = new Socket( AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp ); IPEndPoint localEndPoint = new IPEndPoint( IPAddress.Any, 11000 ); listener.Bind( localEndPoint ); EndPoint ep = (EndPoint)iep; Console....

Are sockets reliable ?

Is it a good idea to use sockets to send data between two servers, or should I use something like MQ for moving data. My questions: are sockets reliable, if I need once only/assured delivery of the data? Are there any other solutions? Thanks. ...

What does STATUS_INVALID_DEVICE_STATE mean?

I am calling WsKSendTo on an opened socket (irp returns success in callback). But WskSendTo on that socket returns c0000184, what is referenced to as STATUS_INVALID_DEVICE_STATE. What kind of errors are addressed by this? Did I miss something in the send routine? psc->dstaddr.sin_family = AF_INET; psc->dstaddr.sin_port = 0x6973; ...

Why UDP socket subscribed to a multicast group is picking up a non-multicast message?

Overview: I have set up a server and a client, where both attempt discovery of each other using UDP. When the server starts up it sends a multicast message (239.1.1.1) that it is alive. When the client starts up it sends a multicast message (239.1.1.2) that it is alive. Both server and client are subscribed to each other's multicast mess...

How to enumerate all IP addresses attached to a machine, in POSIX C?

Background: I'm writing a daemon that makes outgoing TCP/IP connections. It will be running on machines with multiple (non-loopback) IP addresses. I'd like the users to be able to specify, in the daemon's config file, which IP address(es) to use for outgoing connections, or * to use all. The addresses will be used in a rotation, each...

Test to see if a socket is open in linux

I have a linux server program that waits for incoming connections from a client and depending on what command you send it performs a different connection. Here is the pseudo-code setup_socket(); while(1) { listen(); newfile_descriptor = accept(); int command read(newfile_descriptor,&command,sizeof(int)); switch(command) ...

Getting started with socket programming in C# - Best practices

I have seen many resources here on SO about Sockets. I believe none of them covered the details which I wanted to know. In my application, server does all the processing and send periodic updates to the clients. Intention of this post is to cover all the basic ideas required when developing a socket application and discuss the best pra...

TServerSocket: Confusion with Socket Objects

So I'm having this application that verifies weather a user can log-in or not. It consists of multiple Clients (up to 200) and a server that processes the login querys (containing Username, PW and IP). The Server checks weather the user exists and sends an answer back. TLoginQuery is a Record. procedure TLogin_Form.btnLoginClick(Sende...

udpclient.close doesn't always close the socket??

I'm using the code below, it seem sometime the socket is not released How did I found that? by using process explorer(from sysinternal), proprieties on the application then going into TCP/IP tab. I can see the port being used by typing "netstat -a" into a console My problem is, after a while (like 5 weeks) there is like 40 port used...

Programmatically verify if a UDP port is bound in C/C++

Without attempting to bind it ...

Limited sockets to midp?

It seems to me that there is some kind of limitation in socket creation in MIDP. I need to make lots of connections to a server (none concourrent) and in the forth or fith try my app crashes. It crashes in the simulator and in my real device as well. To isolate any possibility of it being influenced by my code, I isolated the following ...

I have a server listening on sockets, whats a good approach to service CPU-bound requests with multiple threads?

I've got an application, written in C++, that uses boost::asio. It listens for requests on a socket, and for each request does some CPU-bound work (e.g. no disk or network i/o), and then responds with a response. This application will run on a multi-core system, so I plan to have (at least) 1 thread per core, to process requests in par...

10057 WSA Exception when SendBuf via Socket

Client: //is called when the client tries to log in procedure TLogin_Form.btnLoginClick(Sender: TObject); var LoginQuery: TQuery; begin //If socket not open, open it if not LoginSocket.Active then begin LoginSocket.Open; end; //create package LoginQuery.Login := ledtName.Text; LoginQuery.Passwort := ledtPasswort...

Java TCP socket: data transfer is slow

I set up a server with a ServerSocket, connect to it with a client machine. They're directly networked through a switch and the ping time is <1ms. Now, I try to push a "lot" of data from the client to the server through the socket's output stream. It takes 23 minutes to transfer 0.6Gb. I can push a much larger file in seconds via scp...

Similar function to GetLastError in objective-C/C?

I'm doing some lovely socket programming in objective-C right now and part of my code is giving me an error (in the setsockopt method call). I was wondering if anyone knows of a similar function to the GetLastError() function in C++ that I could use in objective-C to determine the problem with my code? ...

Writing a "raw" HTTP client in C#

I am trying to write a "raw" HTTP client in C#. You may ask why?? My aim is to implement an HTTP client in J2ME (which can only do GET and limited POST), but first I need to understand the HTTP protocol better (hence the C# attempt). My first attempts are failing: var requestBytes = Encoding.UTF8.GetBytes(@"GET / HTTP/1.1 User-Agent:...