network-programming

How do I properly determine if my client is still connected to the server with C sockets?

微笑、不失礼 提交于 2019-12-25 01:50:03
问题 I have a client connected to a server via C Berkeley sockets. I (try to) periodically check to see if the connection is still valid by calling recv() on the socket with MSG_DONTWAIT and MSG_PEEK. However, I'm finding that this call returns EAGAIN both when the connection is down in some cases (e.g., after the connection's interface is shut down) and when there is simply no data to read. Hence, there is no way for me to distinguish whether the connection is still valid or not using this method

Comparing strings in C - strcmp

孤者浪人 提交于 2019-12-25 01:37:00
问题 I'm having trouble comparing strings in C (with which I am fairly new to). I have socket on this server application waiting to accept data from a client. In this particular portion of my program I want to be able to execute a MySQL query based on the data received from the client. I want to be able to know when the received data has the value of "newuser" to initiate a simple registration procedure. Strcmp is returning a positive 1 value where I believe I should be getting a 0 because the

Conversion from int to byte forcibly results in — Exception in thread “main” java.lang.NumberFormatException

不问归期 提交于 2019-12-25 01:17:42
问题 I was writing a program to convert a String fed IP-Address to IP-Address by utilising the method InetAddress.getByAddress(byte[] addr) . So, what I did was input IP-from the user in the form of String. Parsed it and splitted the IP on . using String.split("\\.") . Then, I started converting that String array into byte array where I am right now stuck on. Please help me to get rid of this situation. Any workaround OR alternate way of accessing this will be heartly appreciated... The code goes

How to change a TLS context option

南楼画角 提交于 2019-12-25 00:26:31
问题 In python, we can specify some TLS context options. For example, this code from the documentation here: client_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT) client_context.options |= ssl.OP_NO_TLSv1 client_context.options |= ssl.OP_NO_TLSv1_1 I do not get this symbol |= . I read what it means but don't get why we use it here? why don't we use = ? Should I use |= to set any option? strangely, I find some examples also int he documentation use &= : ctx = ssl.create_default_context(Purpose

Receive data with UDP protocol and readDatagram

给你一囗甜甜゛ 提交于 2019-12-24 21:35:43
问题 After a first topic that help me send correctly data to someone using UDP Protocol, I have a problem in the reception of these data. This problem is very strange and only happen the first time I launch the function for sending data. The first time, the server only receive the first frame. But after, if I re use the function everything is ok. So here's the code that send data through UDP Protocol (my data is a structure) : void MyUDP::sendUDP() { //Structure to send typedef struct MyStructTag

packet is sent completely somtimes and somtimes is not sent completely

有些话、适合烂在心里 提交于 2019-12-24 21:27:22
问题 @Grismar recommended me to create new topic for the following problem: I wrote a server and client with socket module.For multi connection I used selectors module instead of thread or fork() . Scenario: I have to generate a massive string and send to client.Of course according to a string is generated by client. Indeed client send a query and server generate a result and send to client. I don't have problem for send query to server. Because I have massive string, I decided to split my string

Traceback (most recent call last): File “”, line 1, in AttributeError: module 'socket' has no attribute 'close'

烂漫一生 提交于 2019-12-24 19:48:01
问题 I need to write a program that retrieves the IP addresses of a list of domain names. The simple example can be shown here: >>> import socket >>> socket.gethostbyname('google.com') '172.217.160.14' >>> socket.close() After I try to close the socket, I get this error: Traceback (most recent call last): File "", line 1, in AttributeError: module 'socket' has no attribute 'close' How can I close this socket? I need to close it because my actual program has loop where in each domain name in the

write non-blocking event with with libevent in C programming

 ̄綄美尐妖づ 提交于 2019-12-24 19:29:54
问题 I am newbie in libevent and socket programming that's why I have question about how libevent working as asynchronous and non blocking. Here is the reference code. https://github.com/libevent/libevent/blob/master/sample/http-server.c static void dump_request_cb(struct evhttp_request *req, void *arg) { const char *cmdtype; struct evkeyvalq *headers; struct evkeyval *header; struct evbuffer *buf; printf("Request Start\n"); sleep(30); // delay to read request to check non blocking event. switch

How to get MAC address of connected Access point?

自闭症网瘾萝莉.ら 提交于 2019-12-24 19:19:42
问题 I am using Scapy to sniff access point(AP) beacon packets and also getting all AP beacon packets and it's MAC address nearby AP but I need exact MAC address of connected AP then How to sniff only connected AP beacon frame or How to filter connected AP beacon frame using scapy or any alternate idea. *I am doing it in python 2.7 回答1: Assuming the beacon frame is called pkt. pkt.addr1 is the destination MAC, pkt.addr2 is the source MAC and pkt.addr3 is the MAC address of the AP. You could write

Alloy programming for example network configuration

蓝咒 提交于 2019-12-24 18:54:30
问题 Suppose there are 8 pcs and 1 switch, I want to divide three subnets.how to use alloy language program?Can you give an example? 回答1: The following models a small network. sig IP {} some sig Subnet { range : some IP } abstract sig Node { ips : some IP } sig Router extends Node { subnets : IP -> lone Subnet } { ips = subnets.Subnet all subnet : Subnet { lone subnets.subnet subnets.subnet in subnet.range } } sig PC extends Node {} { one ips } let routes = { disj s1, s2 : Subnet | some r : Router