Posts

Showing posts with the label sockets

TCP Server failing after first response

TCP Server failing after first response NOTE I rewrote this question for the bounty as i was able to figure out how to get the first question solved but didn't want to start a new question. the comments below pertain to the original question, not the revised. Description of Issue My tcp client executes querying the tcp server one time successfully, returns the response, and then subsequent requests to the server from the client fails. Also, if i terminate the client and reload it fails on the first attempt as well. Here's what my command prompt looks like: root@ubuntuT:/home/jon/gocode/udps# ./udpservtcpclient Text to send: SampleQuery Message from server: SampleResponse Text to send: SampleQuery ((End - No Response)) root@ubuntuT:/home/jon/gocode/udps# ./udpservtcpclient Text to send: SampleQuery ((End - No Response)) What I expect I expect to be able to query the tcp server from the tcp client endlessly, and have the tcp server return a response from the UDP Server every tim...

HTTP in Java socket

HTTP in Java socket I want to send a JSON to an already written server (not from me). My problem is that I have an HTTP problem and need to convert it to HTTP. Server message: 2018-06-29 20:02:30.532:WARN:oejh.HttpParser:qtp245475541-15: badMessage: 400 No URI for HttpChannelOverHttp@2bb4ec27{r=0,c=false,a=IDLE,uri=} 2018-06-29 20:03:24.206:WARN:oejh.HttpParser:qtp245475541-18: badMessage: 400 No URI for HttpChannelOverHttp@866a0c9{r=0,c=false,a=IDLE,uri=} Code: public class client { public static void main(String args) { JsonObject js = new JsonObject(); js.addProperty("action","auth"); js.addProperty("type","android"); js.addProperty("token","lalalalalalalalala"); try { Socket ss = new Socket("localhost",3000); PrintWriter out = new PrintWriter(ss.getOutputStream(), true); BufferedReader in = ...

Java Socket reading response from other application

Java Socket reading response from other application I'm currently making a connection from a software to an application using java socket. The code is more or less like this import java.io.*; import java.net.*; import java.util.Scanner; public class Input { public static void main(String args) { try{ Socket s=new Socket("ok",10003); PrintWriter printWriter = new PrintWriter(s.getOutputStream()); Scanner scanner = new Scanner( System.in ); BufferedReader inserver = new BufferedReader(new InputStreamReader(s.getInputStream())); String str = scanner.nextLine(); String hisscanner = "u0002"+str+"u0003"; printWriter.write(hisscanner); s.shutdownInput(); String response = inserver.readLine(); System.out.println("FROM SERVER: " + response); printWriter.close(); s.close(); scanner.close(); }catch (UnknownHostException ex) { System.out.println("Could not connect to the server [Unknown exception]"); } catch (IOException ex) { System.out.pri...

mongodb : listen() attempts to access socket in a forbidden way

mongodb : listen() attempts to access socket in a forbidden way I downloaded 64-bit zipped version of mongodb for windows, created '/data/db' as instructed. Now, when I run "mongod" command, I am getting the following error & the mongodb server shuts down automatically. "ERROR : listen() failed error-10013. An attempt was made to access socket in a way forbidden by its access permissions. " Please help me to clear the firewall settings in windows to prevent this error & run mongodb. I was able to fix the error by using the following command : "mongod --bind_ip="127.0.0.1". :) – Dharshni May 18 '14 at 10:14 Perhaps better to put your comment in an answer and accept it. It can be useful to other users. – kranteg ...

How to receive multiple responses from UDP broadcast

How to receive multiple responses from UDP broadcast I have a case in which i need to send a broadcast a UDP request in the wifi on a specific port and the specific devices i am calling should return some info so i can determine how much are they in this network. So far i have this: public class UDP extends AsyncTask<Void, Void, String> { @Override protected String doInBackground(Void... voids) { String text = ""; int server_port = 7432; DatagramPacket receivePacket = null; DatagramSocket clientSocket = null; try { clientSocket = new DatagramSocket(); clientSocket.setSoTimeout(5); InetAddress IPAddress = InetAddress.getByName("255.255.255.255"); byte sendData = ("02904").getBytes(); byte receiveData = new byte[12]; DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, server_port); clientSo...