I wrote a program to transfer a file using tcp connection, where I closed socket since the receiver need to detect the end-of--file. But now I like to extend it to multiple file for which i should not close the socket until all the files are send. I can't find a way for this. So how to resolve it.
I'm trying to send a text file over a socket, from client to server, but I doesn't work. I will demonstrate a part of the code that isn't working.
The critical part of the server look like this:
while(true) { try { Socket socket = fileSocket.accept(); out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream())); in = new BufferedReader(new InputStreamReader(socket.getInputStream())); String s = in.readLine();
And the client like this:
Socket = new Socket(address, number); BufferedWriter out = new BufferedWriter(new OutputStreamWriter(Socket.getOutputStream())); BufferedReader in = new BufferedReader(new InputStreamReader(Socket.getInputStream())); BufferedReader fileIn = new BufferedReader(new FileReader(filename)); String s = fileIn.readLine(); out.write(s);
Now I want the s in the server to hold the same string as s in the client, but the server can't read the stream - nothing happens. I know that readLine() reads until a new line character, but it doesn't word to write and read a single character either.
I have written a java code to transfer files from one server to another using the concept of socket programming. I got the codes from another java forum that meet my requirements. The program is said to transfer large sized files (like .mkv , .mprg movies) from one machine to another and can be used to transfer files of all formats. But after running the codes I found that the program is not able to transfer large sized files such as movies and even pdf of sizes 80mb or 111mb. When i transfer small sized files, it gets transferred and the output shows that. You can run the codes and observe it. But when i try to transfer large sized files, the program goes on running for hours. The large sized files are not getting transferred. The program has used bytebuffer but still this error occurs. The codes are as follows (I got them from this site [URL] ....)
**ClientMain.java**
import java.io.IOException; import java.net.Socket; public class ClientMain { private DirectoryTxr transmitter = null; Socket clientSocket = null;
[Code] .....
1. ClientMain.java and DirectoryTxr.java are the two classes under client application. 2. ServerMain.java and DirectoryRcr.java are the two classes under Server application. 3. run the ClientMain.java and ServerMain.java simultaneously
Also specify the source directory, destination directory and host address of the machine in which server is running in the ClientMain.java (as per your computer). Here we are not specifying source file, instead a source directory or folder is specifying. So the entire files of source directory will be transferred.
I have written a java code to transfer files from one server to another using the concept of socket programming. I got the codes from another java forum that meet my requirements. The program is said to transfer large sized files (like .mkv , .mprg movies) from one machine to another and can be used to transfer files of all formats. But after running the codes I found that the program is not able to transfer large sized files such as movies and even pdf of sizes 80mb or 111mb. When i transfer small sized files, it gets transferred and the output shows that. You can run the codes and observe it. But when i try to transfer large sized files, the program goes on running for hours. The large sized files are not getting transferred. The program has used bytebuffer but still this error occurs. The codes are as follows (I got them from this site [URL] ....)
**ClientMain.java**
import java.io.IOException; import java.net.Socket; public class ClientMain { private DirectoryTxr transmitter = null; Socket clientSocket = null;
[Code] ....
Note that:-
1. ClientMain.java and DirectoryTxr.java are the two classes under client application. 2. ServerMain.java and DirectoryRcr.java are the two classes under Server application. 3. run the ClientMain.java and ServerMain.java simultaneously
Also specify the source directory, destination directory and host address of the machine in which server is running in the ClientMain.java(as per your computer). Here we are not specifying source file ,instead a source directory or folder is specifying.So the entire files of source directory will be transferred.
<%@ page import="javax.print.*"%> <%@ page import="javax.print.attribute.*"%> <%@ page import="java.io.*"%> <%out.println("Printing..."); String filename = "c:/20140505_3_40.txt";//this is the text file i want to send to printer // am using tomcat 8 PrintRequestAttributeSet pras = new HashPrintRequestAttributeSet();
I'm trying to do a program that send a single file from a client to a default directory of a Server. The program use the datagramSocket and datagramPacket for the transfer via UDP. The client sent the packet of the file correctly and the server start the receiving but every time the Server class crashes after it's receiving 4/5 packet (exactly 8192 byte)
Then i put the code of the 2 class and the 2 output.
OUTPUT CLIENT:
PROGRAM TRANSFER PACKAGES name of file is : Doc1.pdf his dimension: 11408 byte
PROGRAM TRANSFER PACKAGES START NEW CONNECTION Directory: C:prova Server waiting in port: 9876 Waiting Client... Name of file is : Doc1.pdf Dimension : 11408
[Code] ....
In this point the program go in loop and didn't anything. I don't understand how can i resolve it...
I have a WindowClosing(WindowEvent e) method, but when I close my window it isn't doing anything inside the method. I am making a launcher and I want to make it so when the actual game window is closed it makes the launcher window visible again.
Java Code: public void windowClosing(WindowEvent e) { this.jf.setVisible(true); } mh_sh_highlight_all('java');
I recently made a game. But, I want to package it and give it to my friends. I know that I can create a jar of it and add the images to the folder, but what I would absolutely love is for it to just be a picture with the game name and click to run. The second thing is to replace that java icon to an icon of my preference, which I have been told numerous times to do with
if the above code is to launch another application using java then how can I close/exit the same(another) application using java code once I press the exit button of my java app.
I'm going through a file (MySQL dump) and I wish to take the SQL and create individual files for each table (as opposed to what I do now, which is just run through the whole thing).
Now, this all works fine - but what I want to do is create a separate .sql file for each table.
However, I can't figure out the best way to do this - how do I create a new FileWriter (or instance of whatever class is required) as I'm going through the while loop? That or pointing the same one to different files as I go through the loop.
It can be assumed that the file may exceed RAM - I want to do it line by line rather than slurping the entire file as a string and "cheating" that way.
There appear to be many (a bewildering amount of) I/O options and I'm just unsure.
I am modifying existing code to display graph after pressing calculate button. The graph pop ups in new controller/window. The pop up disappears after closing the application entirely. However I have trouble figuring out if it is possible to close that old/previous pop up and new pop up appears when calculate button is pressed again. Or at least reuse the pop up to display a new graph.
public class AdamCalculationApp extends AbstractCalculation { /** * Does a calculation. */ public void calculate() { // Does a calculation control.println("Adam Calculation button pressed."); double k = control.getDouble("k value"); // String must match argument of setValue control.println("k*k = "+(k*k)); control.println("random = "+Math.random());
While analyzing the thread dumps for a performance issue in our java ee web application, I see many thread dumps stuck on a closing brace of a while loop. Here is the code block of a third party library bitronix (version 1.3.3 SNAPSHOT)
public XAResourceHolderState findXAResourceHolderState(XAResource xaResource) throws BitronixSystemException { Iterator it = resources.iterator(); while (it.hasNext()) { XAResourceHolderState xaResourceHolderState = (XAResourceHolderState) it.next(); if (xaResourceHolderState.getXAResource() == xaResource) return xaResourceHolderState; } return null; }
The thread dumps indicate that many threads are stuck in RUNNABLE state on line number 07. What could be the possible reasons on why a thread could get stuck on a closing brace of a while loop? The iterator of the while loop is a custom implementation.
I have a Dialog with no buttons (the dialog pane contains some graphic elements which act as my buttons). I show the dialog and try to click the close window button on the dialogs title bar, and the dialog does not close! I read the docs and it appears that only dialogs that have one or more buttons can be abnormally closed (and only under certain well defined sensible conditions). How can I abnormally close a dialog with no buttons?
I would like to understand how does multipart/form-data works during file upload scenario's, Does it chunks the data from client to server while transferring the files ?
I configured a connection pool in tomcat 7. For every database activity I get a connection from the pool. Do I have to close the connection like other regular connection after the database operation is done? If I close the connection will it have any effect on the connection pool?
I'm developing a web-based chatting system using JSP and socket.
The problem i am facing is that the sender can send message but on the receiver side we have to manually refresh the page. The sender stays into blocking mode until the receiver refresh its page !
after that i've implemented auto-refresh on the receiver side and "Connection Refused" exception is generated.
final ServerSocket serverSocketConn = new ServerSocket(9000); while (true) { try { Socket socketConn1 = serverSocketConn.accept(); new Thread(new ConnectionHandler(socketConn1)).start();
[Code] .....
I managed to convert this final DatagramSocket serverSocketConn = new DatagramSocket (9000);
Now I am stuck here
Socket socketConn1 = serverSocketConn.accept(); new Thread(new ConnectionHandler(socketConn1)).start();
Can I use this or I need to create a manual thread pooling for UDP ?
I can have up to 100,000 simultaneous connections to a udp socket, which needs to be handled by separate threads. Each of the connections talk to a c program on an embedded device that sends and responds with an array of unsigned chars. Now Java does not have an unsigned char type. The closest you can use is a short. But DatagramPacket requires a byte argument:
public class Socket { public Socket(int port) throws IOException { new SocketThread().start(); } } public class SocketThread extends Thread { protected DatagramSocket socket = null;
[Code] .....
So how can I go about reading and writing unsigned chars over a udp socket?
if i send messages as in the code below, is there a way to read only one message, if the client doesn't know how long it is (or if he only knows the maximum length)?in the documentation it says, that the method read(byte[]) reads until no data ist available or end of file is decteted. What does the latter mean? Can i extend the array that i sent by a byte that signals the end? Here is my Code:
Server
public class Server implements Runnable{ ServerSocket server; HashMap<Short,Socket> clients; public Server(){ clients = new HashMap<>();
[code]....
Both are startet in seperate threads. At the moment the first output of the client is "12 bytes read", and then continously "-1 bytes read"(because the server closes).
I have been working with socket programming. I was trying to develop a two way communication from server to client. The data is being received when sent from server to client but there is a problem when I am sending from client to server.
I am getting an error as "Socket is closed" pointing to the line where I have created a BufferedReader. I have simplified some part of my code to be very specific.
Code attached.
import java.io.*; import java.net.*; import java.util.*; public class Server { public static void main(String args[]) { String id="policeone"; int hashcodeid=0;
[Code] ....
Error::
Receiving string from client: 'java.net.SocketException: Socket is closed at java.net.Socket.getInputStream(Socket.java:872) at Server.main(Server.java:51)
I want to download objects (css , jpeg, html ,png ) using sockets in java without using httpurlconnection . How can i do this with simple socket library ?