network-programming

socket select fails with operation in progress - Non blocking mode

≯℡__Kan透↙ 提交于 2020-01-05 06:27:10
问题 Our application uses a non-blocking socket usage with connect and select operations (c code). The pusedo code is as below unsigned int ConnectToServer(struct sockaddr_in *pSelfAddr,struct sockaddr_in *pDestAddr) { int sktConnect = -1; sktConnect = socket(AF_INET,SOCK_STREAM,0); if(sktConnect == INVALID_SOCKET) return -1; fcntl(sktConnect,F_SETFL,fcntl(sktConnect,F_GETFL) | O_NONBLOCK); if(pSelfAddr != 0) { if(bind(sktConnect,(const struct sockaddr*)(void *)pSelfAddr,sizeof(*pSelfAddr)) != 0)

How can I implement a proxy that handles both TCP and UDP in java? [closed]

冷暖自知 提交于 2020-01-05 05:51:08
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I was looking into proxy implementations (I am interested in using Java as programming language). I was wondering, is a proxy supposed to work on all protocols? E.g. TCP and UDP A single protocol, e.g. TCP only? Are proxies usually application level e.g. HTTP ? Is it possible to implement a proxy that can proxy

select() on STDIN and Incoming Socket

牧云@^-^@ 提交于 2020-01-05 04:25:12
问题 I'm trying to write a very basic chat client in C which communicates with another machine using sockets, and I'm having some issues with understanding select. Here's a quick snippet of the relevant code. while(1) { FD_ZERO(&readfds); FD_ZERO(&writefds); FD_SET(STDIN, &writefds); FD_SET(connectFD, &readfds); select(connectFD+1, &readfds, &writefds, NULL, NULL); if(FD_ISSET(connectFD, &readfds) != 0) { char buf[1024]; memset(buf, 0, sizeof(buf)); int lastBit; lastBit = recv(connectFD, buf,

BIND ERROR : Address already in use

 ̄綄美尐妖づ 提交于 2020-01-04 01:59:07
问题 I am learning socket programming in c, I wrote this simple program to accept connections on port 5072. i connect to it using telnet. This works fine the first time but when i try to run it again immediately it fails showing BIND : Address already in use, but then again starts to work after a minute or so. What am i doing wromg? #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netdb.h> #include <arpa/inet.h> #include <stdlib.h> int main(){ /

Does Selector.close() closes all client sockets?

六眼飞鱼酱① 提交于 2020-01-03 18:39:12
问题 I am new to nio sockets, I have written a server using nio sockets and now I am trying to write shutdown hook to make sure a graceful exit by cleaning up resources. My question is does Selector.close() method closes all client sockets? if not please let me know how can I access all the client sockets without having a separate list of them. Java Doc says following for selector.close() method Closes this selector. If a thread is currently blocked in one of this selector's selection methods then

Programmatically determine if ip address is assigned via dhcp or manually set in Java

血红的双手。 提交于 2020-01-03 08:35:13
问题 Is there any way to discover if a local network interface has it's address assigned via DHCP or if it is statically set through Java? 回答1: So, as you requested Win NT 'solution' only, here is my code.It lists network interfaces with current configured values. Note EnableDHCP registry key value, I think this is the point. As I already mentioned in comment under your question, you need as least simple JNI wrapper. Hope this helps. more info here : http://support.microsoft.com/kb/314053 #include

maxevents parameter in epoll_wait() and the events array size

人盡茶涼 提交于 2020-01-03 06:26:39
问题 In epoll usage, it is usually like the following: struct epoll_event ev,events[20]; epfd=epoll_create(256); 。。。 nfds=epoll_wait(epfd,events,40,500); Some articles are saying that the maxevents parameter in epoll_wait (namely the 40 in epoll_wait(epfd,events,40,500); ) should not exceed the size parameter in epoll_create (namely the 256 ). I think the maxevents parameter should not exceed 20 in ev, events[20] , because events can only be registered to 20 events elements; otherwise, if there

WinSock program in C, works only on local computer

房东的猫 提交于 2020-01-03 02:50:13
问题 I'm a newbie in Network Programming, started to learn how to use WinSock in C. I don't have any knowledge in Networking right now. Anyway, I've written the following code for Client and Server, using WinSock. Server: #include <stdio.h> #include <stdlib.h> #include <winsock2.h> #include <ws2tcpip.h> #define MY_ERROR 1 #define PORT 7777 #define MAX_NUM_CLIENTS 1 /* I don't know how to thread right now. */ #define MAX_CLIENT_MSG_LEN 1000 int main() { WSADATA wsa; SOCKET mySocket, acceptSocket;

What is the 'wildcard address' In the context of UDP Broadcasts?

假如想象 提交于 2020-01-03 02:04:56
问题 Referring to the Java 6 API docs for the DatagramSocket class: UDP broadcasts sends are always enabled on a DatagramSocket. In order to receive broadcast packets a DatagramSocket should be bound to the wildcard address . In some implementations, broadcast packets may also be received when a DatagramSocket is bound to a more specific address. Could someone tell me what the 'wildcard address' is? And is the following valid for listening for UDP broadcasts: MulticastSocket socket = new

Send data over the network C#

断了今生、忘了曾经 提交于 2020-01-03 02:04:14
问题 I try to send a string over the network, this is my code: IPEndPoint serverEndPoint = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 25); TcpClient client = new TcpClient(serverEndPoint); Socket socket = client.Client; byte[] data = Encoding.ASCII.GetBytes(response); socket.Send(data, data.Length, SocketFlags.None); socket.Close(); client.Close(); When I run it I got System.Net.Sockets.SocketException 回答1: If you are using a connectionless protocol, you must call Connect before calling Send, or