Is it possible to know which connection sent data wiht recv()? Current setup is - Main Thread spins and waits - Thread 1 - do stuff unimportant to socket - Thread 2 - accept() -> keep linked list of accetpted sockets - Thread 3 - recv() -> can I know which IP addr/connection sent me the data I am currently reading? Thank you :) Ryan

Member Avatar
Member Avatar
+0 forum 1

I'm trying to understand socket programming in python by experimenting a little. I'm trying to create a server that you can connect to by telnet and that echoes what you type in the telnet prompt. I don't want to start using threads just yet. This is my code. [CODE]import socket host = "127.0.0.1" port = 8080 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.bind((host,port)) sock.listen(1) remote, address = sock.accept() print "Connection from", address while True: data = sock.recv(1024) remote.send(data) [/CODE] The server starts without errors, but when I connect with the telnet client I get, on the client side: [ICODE]> telnet 127.0.0.1 8080 …

Member Avatar
Member Avatar
+0 forum 4

A service running in the Server is listening to port 2978 on 1xx.xxx.xx.xx for incoming connections! My PHP code receives URL data through get method. A tcp connection has to be established with the 'service' on that port and the data received from the URL should be sent to the service. The service responds with another data to the same port. this data should be obtained by the code and be saved in a file. I've written the code. But its showing error! help me pls!! [CODE]#!/usr/local/php5/bin/php-cgi <?php $CONTENT = $_GET["DATA"]." "; //fsockopen("tcp://1xx.xxx.xx.xx",2978 , $errno, $errstr, 30); echo urldecode($CONTENT); $Handle …

Member Avatar
Member Avatar
+0 forum 1

This is the server code for the udp server/client program . There are no errors except when you run the program the ff error occurs: [COLOR="Red"]Exception in thread "main" java.lang.NullPointerException at udptry2.UDPServerbackup2.main(UDPServerbackup2.java:44) Java Result: 1[/COLOR] the client side works how it should just this part of the program [CODE] package udptry2; import java.io.*; import java.net.*; import java.util.*; import java.lang.*; import java.lang.String; class UDPServerbackup2 { public static void main(String args[]) throws Exception { Scanner x = null ; DatagramSocket serverSocket = new DatagramSocket(6666); byte[] receiveData = new byte[1024]; byte[] receiveData2 = new byte[1024]; byte[] sendData = new byte[1024]; byte[] sendData2 = …

Member Avatar
Member Avatar
+0 forum 1

This is a simple server/client program. What i'm trying to do is let the server send a message to the client, the client should receive this message and print this message on screen. When i run the program the server prints "Server start" like its supposed to but nothing happens on the client part ...Pls Help! [CODE] import java.net.*; import java.io.*; public class server1 { public static void main(String args[]) throws Exception { try { DatagramSocket serverSocket = new DatagramSocket(); InetAddress address = InetAddress.getByName("localhost"); byte sendData[]=new byte[2048]; byte receiveData[]=new byte[2048]; System.out.println("Server Start"); String Welcome = "You are now connected to …

Member Avatar
Member Avatar
+0 forum 1

[CODE]while(size!=0) { printf("loop start"); printf("File Size in int: %d \n",size); byte_count = recv(sock,recv_data, 1024,0); recv_data[byte_count] = '\0'; printf("hhahaha %d \n",10); printf("char is:%c \n",recv_data[0]); //fputc(recv_data[0], fpW); size=size-1; printf("loop end"); } fclose(fpW); This is a piece of Client side code .. i am sending data from Server Side but when i receive it on client side the recv call is blocked the code how m i sending data from server is: FILE *fp; int ch; if((fp = fopen("file.txt","rb"))==NULL) { printf("Cannot open Source file.\n"); exit(1); } struct stat fileInfo; stat("file.txt", &fileInfo); int size=(int)fileInfo.st_size; printf("File Size: %d \n",size); fflush(stdout); char msg1[10]; sprintf(msg1,"%i",size); printf("File Size: …

Member Avatar
Member Avatar
+0 forum 5

The End.