![]() |
#10
|
|||
|
|||
One question and a rather unstructured protocol of this night:
1) if I do host = "localhost" addr = (host,PORT) InSocket.bind(addr) should it not bind the socket to localhost? Should I not be able to access it by telnet localhost 49213 Where Port is 49213 I also tried the current IP-Adress e.g. telnet 169.254.148.117 49213 -------------- The following is more like a protocol, maybe not very useful... Tried a lot around to get a connection between Java and your Socket. Port is 49213 Why do I not get a reply when I do telnet 169.254.148.117 49213 Other Printouts: COMPUTER_NAME OGL1 COMPUTER_NAME OGL1COMPUTER_IP_ADDRESS 169.254.148.117 I also tried (offline and online) telnet localhost 49213 Only get connection failed. From another Python Client I receive date: e.g. from socket import * # Set the socket parameters host = "localhost" port = 21567 buf = 1024 addr = (host,port) # Create socket UDPSock = socket(AF_INET,SOCK_DGRAM) def_msg = "===Enter message to send to server==="; print "\n",def_msg # Send messages while (1): data = raw_input('>> ') if not data: break else: if(UDPSock.sendto(data,addr)): print "Sending message '",data,"'.....<done>" # Close socket UDPSock.close() From Java it works if I use try { DatagramSocket sock = new DatagramSocket(); InetAddress server = InetAddress.getByName(host); if (timeout > 0) sock.setSoTimeout(timeout * 1000); // millisec BufferedReader in = new BufferedReader(new InputStreamReader(System.in)); PrintWriter out = new PrintWriter(System.out, true); String line; while ((line = "hallo12") != null) { byte[] req = line.getBytes(), ans = new byte[1024]; DatagramPacket r = new DatagramPacket(req, req.length, server, port), a = new DatagramPacket(ans, ans.length); .... but normal Client-Sockets do not work e.g. Socket kkSocket = null; PrintWriter out = null; BufferedReader in = null; InetAddress server_name = null; try { //InetAddress server_name=localhost.byN; //String COMPUTER_NAME = ; String host = "localhost"; InetAddress server = InetAddress.getByName(host); kkSocket = new Socket(server, 21567); out = new PrintWriter(kkSocket.getOutputStream(), true); in = new BufferedReader(new InputStreamReader(kkSocket.getInputStream())); |
|
|