sockets

Sending http headers with python

自古美人都是妖i 提交于 2021-02-06 11:37:13
问题 I've set up a little script that should feed a client with html. import socket sock = socket.socket() sock.bind(('', 8080)) sock.listen(5) client, adress = sock.accept() print "Incoming:", adress print client.recv(1024) print client.send("Content-Type: text/html\n\n") client.send('<html><body></body></html>') print "Answering ..." print "Finished." import os os.system("pause") But it is shown as plain text in the browser. Can you please tell what I need to do ? I just can't find something in

Sending http headers with python

孤街醉人 提交于 2021-02-06 11:36:50
问题 I've set up a little script that should feed a client with html. import socket sock = socket.socket() sock.bind(('', 8080)) sock.listen(5) client, adress = sock.accept() print "Incoming:", adress print client.recv(1024) print client.send("Content-Type: text/html\n\n") client.send('<html><body></body></html>') print "Answering ..." print "Finished." import os os.system("pause") But it is shown as plain text in the browser. Can you please tell what I need to do ? I just can't find something in

Address family not supported by protocol

空扰寡人 提交于 2021-02-06 10:17:46
问题 Following code is a socket programming sample for a TCP client. But when I run this, connect() is returned as Address family not supported by protocol. I have heard, this problem will happen if the platform does not support ipv6. But AF_INET I wrote is ipv4. Also my server, that is CentOS6.4, is configured within an inet6 addr . Does anyone know why? #include <stdio.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> int main(){ struct sockaddr_in

Socket handle transfer between independent processes

自古美人都是妖i 提交于 2021-02-06 09:21:33
问题 I am doing some experiments in socket programming(in unix environment). What I am trying is Client sends request to Server. Server should send the clients socket to Worker(An Independent process) Worker should reply back to Client. Is this possible? This scenario works if Worker is a child of Server. If Server and Worker are independent processes does this work? If yes can somebody give me some ideas about this ? Is there any samples available for this type of scenario ? 回答1: The Linux

Socket handle transfer between independent processes

大城市里の小女人 提交于 2021-02-06 09:20:08
问题 I am doing some experiments in socket programming(in unix environment). What I am trying is Client sends request to Server. Server should send the clients socket to Worker(An Independent process) Worker should reply back to Client. Is this possible? This scenario works if Worker is a child of Server. If Server and Worker are independent processes does this work? If yes can somebody give me some ideas about this ? Is there any samples available for this type of scenario ? 回答1: The Linux

How can I stream audio from the microphone of an iPhone to a Mac/PC via sockets or a framework?

余生长醉 提交于 2021-02-05 20:34:15
问题 How can I stream audio from the microphone of an iPhone to a Mac/PC? Is there already some framework for this, or can I just send audio over sockets. I'm new to sockets though. Basically, I want to be able to speak into the iPhone, and the computer will receive the iPhone's mic input as its own mic input for computers that do not have microphones. I already have an app that makes a bonjour connection to a Mac, which runs a very simple server, and the iPhone can send text to the computer, but

Spring Integration and TCP server socket - how can I send a message to a client?

柔情痞子 提交于 2021-02-05 20:01:35
问题 I'm trying to create a server in Spring that's listening on a TCP port and accepts connections. I know how to route incoming requests to my service, and it can respond to those. However I would like to send messages to certain clients without any request received. For example, sometimes I have to inform a client about that it has got a message. To do this, I think I need a way to identify the clients, e.g. by letting them log in. Is there a way to have a "session" object for each active

Get IP-address by URL

二次信任 提交于 2021-02-05 12:27:53
问题 This works target.sin_addr.s_addr = inet_addr("127.0.0.1"); but I want to put the IP from a website URL I have tried const char host[] = "http://www.google.com/"; struct hostent *host_ip; host_ip = gethostbyaddr(host, strlen(host), 0); I of corse did WSAStartup before I used gethostbyaddr(); I've tried this target.sin_addr.s_addr = inet_addr(host_ip); I've tried a few simmilar ones too but it isn't working. Could someone show me how to do this correctly. Thank you! EDIT: When I do host_ip =

TCP socket python

我只是一个虾纸丫 提交于 2021-02-05 12:11:29
问题 i am using tcp socket for forwarding data (as class with type of request, and data) between server and client. When i send 6 object of order from client, the server get only 5 object of order, 1 is lost, but tcp is reliable protocol... (sometimes the server get 6 but usually get 5) Here's the client code HEADERSIZE = 10 PORT = 3000 SIZE = 4096 HOST = '127.0.0.1' soc = None ing_map = None def connect_to_client(): s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.connect((HOST, PORT))

Unable to read all bytes using InputStream read API?

拈花ヽ惹草 提交于 2021-02-05 11:34:31
问题 I am having problem reading image bytes in java socket. My iOS client is sending an image here, and it needs to read the total bytes and store that as image on the server end. It works very fine, when i tested through iOS simulator . Because, If I test in simulator, it sends the image upto 46,577 bytes . It reads all very quickly and properly. If I test the same code sending image from an iPhone device, its also sending around " 45, 301 bytes ", but socket code is able to read only some " 21,