sockets

Using public IP address in sockets

大兔子大兔子 提交于 2021-02-08 10:48:29
问题 I am new to socket programming. My sockets work with localhost or local ip. But why can't I create a socket server with my public ip? When I try to do this in python, it complains "cannot assign requested address". import socket s=socket.socket() host="address" port=5000 s.bind((host, port)) s.listen(5) while True: c, addr=s.accept() result=c.recv(1024) print(result.decode('utf-8')) c.send(""" test """.encode('utf-8')) c.close() My IP I got from this website:http://whatismyip.host/ 回答1: A

Why no error when setting socket send/receive buffer size higher than sysctl max?

谁都会走 提交于 2021-02-08 10:21:04
问题 Why no error when setting socket send/receive buffer size higher than sysctl max (as I have demonstrated below)? is no error the "expected behavior"? My sysctl values for socket rmem_max and wmem_max are both set to 212992: net.core.rmem_default = 212992 net.core.rmem_max = 212992 net.core.wmem_default = 212992 net.core.wmem_max = 212992 net.ipv4.tcp_rmem = 4096 87380 6291456 net.ipv4.tcp_wmem = 4096 16384 4194304 net.ipv4.udp_rmem_min = 4096 net.ipv4.udp_wmem_min = 4096 vm.lowmem_reserve

How to connect client and server with the help of ip address which are connected to internet through different wifi?

一个人想着一个人 提交于 2021-02-08 10:14:54
问题 I am using a laptop as my server and a mobile device as my client. I need to send messages between them. I am able to do that by using the local ip address of the laptop and connecting them both to the same wifi network. But how I do use the ip address if I need to send messages though they are connected to different internet through different wifi networks. This is the code in client: client = new Socket("192.168.0.103", 4444); //local ip address of server This is the code in server:

using sockets to fetch a webpage with java

霸气de小男生 提交于 2021-02-08 10:13:07
问题 I'd like to fetch a webpage, just fetching the data (not parsing or rendering anything), just catch the data returned after a http request. I'm trying to do this using the high-level Class Socket of the JavaRuntime Library. I wonder if this is possible since I'm not at ease figuring out the beneath layer used for this two-point communication or I don't know if the trouble is coming from my own system. . Here's what my code is doing: 1) setting the socket. this.socket = new Socket( "www

How to resolve IPv4 address from IPv4 mapped IPv6 address?

元气小坏坏 提交于 2021-02-08 10:00:12
问题 How to get the IPv4 address from IPv4-mapped IPv6 addresses? For e.g I have an IP address ::FFFF:129.144.52.38 . from this, I need to extract 129.144.52.38 . Is there any API for this purpose? I can identify IPv6 or IPv4 address family by using the following function int getaddrfamily(const char *addr) { struct addrinfo hint, *info =0; memset(&hint, 0, sizeof(hint)); hint.ai_family = AF_UNSPEC; // Uncomment this to disable DNS lookup //hint.ai_flags = AI_NUMERICHOST; int ret = getaddrinfo

Link two computers with Socket in Java

五迷三道 提交于 2021-02-08 09:59:05
问题 I have a server and a client in Java, both work in localhost or with my machine IP, but when I tells a IP from another computer in my local network, it tells "Exception occurred: Connection refused: connect"! Here is my code: ChatClient.java package programmingchat; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.Socket; import java.net.UnknownHostException; import java.util

Link two computers with Socket in Java

白昼怎懂夜的黑 提交于 2021-02-08 09:58:53
问题 I have a server and a client in Java, both work in localhost or with my machine IP, but when I tells a IP from another computer in my local network, it tells "Exception occurred: Connection refused: connect"! Here is my code: ChatClient.java package programmingchat; import java.io.BufferedReader; import java.io.DataOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStreamReader; import java.net.Socket; import java.net.UnknownHostException; import java.util

TCP - possible for same client-side port to be used for different connections by different applications simlutaneously?

一世执手 提交于 2021-02-08 09:25:29
问题 Is it possible in TCP for different processes not sharing the same executable image (so no fork() for example) to use a same client-side port on Windows, Linux or OSX? This is specifically related to the socket options SO_REUSEADDR and SO_REUSEPORT set using setsockopt() I believe. As far as I've read, I believe it is possible for the same process/image to do this, but I haven't found information as to multiple processes/images. I would imagine it is theoretically possible since each socket

Can one reliably connect a TCP socket to itself?

蓝咒 提交于 2021-02-08 08:33:29
问题 I am wondering whether it is possible to reliably connect a TCP socket to itself -- that is, to get just one socket where whatever you send() on you receive back through recv(). I saw that this can happen (e.g., here, here, and here), but none of these posts explain how to do this programmatically and reliably (i.e., this is usually touted as a curiosity, rather than a feature one would use deliberately). I'm interested in a solution for Windows, Mac, and Linux. Just for completeness, please

Why is ZeroMQ poller not receiving messages (python)?

孤人 提交于 2021-02-08 08:24:47
问题 I'm trying to use the ZeroMQ Poller() functionality with two sockets in python: import zmq # Prepare our context and sockets context = zmq.Context() receiver = context.socket(zmq.DEALER) receiver.connect("ipc:///tmp/interface-transducer") subscriber = context.socket(zmq.SUB) subscriber.bind("ipc:///tmp/fast-service") subscriber.setsockopt(zmq.SUBSCRIBE, b"10001") # Initialize poll set poller = zmq.Poller() poller.register(receiver, zmq.POLLIN) poller.register(subscriber, zmq.POLLIN) # Process