network-programming

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

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:

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

How to get the requested file name in BaseHTTPServer in python?

允我心安 提交于 2021-02-08 09:10:40
问题 I'm writing an HTTP server in Python and I need to get the name of the requested file from the sent request in order to send from from the server Here is my code: from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer import os.path from os import curdir, sep PortNum = 8080 class myHandler(BaseHTTPRequestHandler): #Handler for the GET requests def do_GET(self): if self.path=="/": print os.path.splitext(self.path)[0] print self.path print "my code" self.path="/index_example3.html" try:

How to get the requested file name in BaseHTTPServer in python?

喜你入骨 提交于 2021-02-08 09:09:33
问题 I'm writing an HTTP server in Python and I need to get the name of the requested file from the sent request in order to send from from the server Here is my code: from BaseHTTPServer import BaseHTTPRequestHandler,HTTPServer import os.path from os import curdir, sep PortNum = 8080 class myHandler(BaseHTTPRequestHandler): #Handler for the GET requests def do_GET(self): if self.path=="/": print os.path.splitext(self.path)[0] print self.path print "my code" self.path="/index_example3.html" try:

How to detect unsecured wifi network from iOS App

谁说我不能喝 提交于 2021-02-07 20:42:01
问题 I would like to detect the presence of unsecured wifi network in my app. Is there any public iOS API available to achieve the same? 回答1: There is no documented API to get that information. If you application needs to send and receive sensitive data across the network, you should generally assume that no connection is secured. 回答2: I would suggest you use an SSL connection for your web service. Then the data that leaves will be encrypted. 回答3: Have a look at the stumbler application and in

How to detect unsecured wifi network from iOS App

强颜欢笑 提交于 2021-02-07 20:40:18
问题 I would like to detect the presence of unsecured wifi network in my app. Is there any public iOS API available to achieve the same? 回答1: There is no documented API to get that information. If you application needs to send and receive sensitive data across the network, you should generally assume that no connection is secured. 回答2: I would suggest you use an SSL connection for your web service. Then the data that leaves will be encrypted. 回答3: Have a look at the stumbler application and in

Is transmitting a file over multiple sockets faster than just using one socket?

不问归期 提交于 2021-02-07 14:32:09
问题 In this old project (from 2002), It says that if you split a file into multiple chunks and then transmit each chunk using a different socket, it will arrive much faster than transmitting it as a whole using one socket. I also remember reading (many years ago) that some download manager also uses this technique. How accurate is this? 回答1: Given that a single TCP connection with large windows or small RTT can saturate any network link, I don't see what benefit you expect from multiple TCP

Is transmitting a file over multiple sockets faster than just using one socket?

百般思念 提交于 2021-02-07 14:31:13
问题 In this old project (from 2002), It says that if you split a file into multiple chunks and then transmit each chunk using a different socket, it will arrive much faster than transmitting it as a whole using one socket. I also remember reading (many years ago) that some download manager also uses this technique. How accurate is this? 回答1: Given that a single TCP connection with large windows or small RTT can saturate any network link, I don't see what benefit you expect from multiple TCP

Usage of select() for timeout

房东的猫 提交于 2021-02-07 14:16:07
问题 I was only able to set maximum of 20 seconds as the timeout parameter in select () API. Whatever value i gave above 20, select() is returning after 20 seconds itself... So i was trying to write a loop for the timeout of 1 minute like this int timeoutcount = 0; do { FD_ZERO(&fd); FD_SET(sock,&fd); timeout.tv_sec = 20; timeout.tv_usec = 0; rc = select (sock+1,&fd,null,null,&timeout); if(rc ==0) timeoutcount += 20; } while(rc ==0 && timeoutcount <60) please help me out...am i going in the