I want to send a message to a specific client in a server. This is my code and what I tried(I have only given you 3 classes in which I believe I have the problem).
TextClient: import java.io.*; import java.net.*; import java.util.ArrayList; import java.util.Scanner; import java.util.concurrent.TimeUnit; public class TextClient { public TextClient() {
I have a problem on how to make my client to send the object to a server.
So I have one interface called "RMIInterface" and client "RMIClient" and server "RMIServer":
RMIInterface interface RMIInterface { public String getMessage(String text) throws RemoteException; } RMIClient public class RMIClient {
[code]....
With this program I can connect to a Server with a Client, and print in Client console a message.But, how can I send message from a client to a server, and print that message in server console output?
make the simpliest example with sending a message to a server, edit inteface header code to public interface RMIInterface extends Remote, I forgot to add.
I want to send a message to a specific client in a server. This is my code and what I tried(I have only given you 3 classes in which I believe I have the problem).
TextClient:
import java.io.*; import java.net.*; import java.util.ArrayList; import java.util.Scanner; import java.util.concurrent.TimeUnit; public class TextClient { public TextClient() {
Firstly, my code is just a demo of my multiplayer game (2 or more players can play simultaneously) to demonstrate my problem without any extra things. I have successfully implemented peer-to-peer (P2P) communication in my game. Later, I decided to add support for client-server communication (ie a central server which is also a player) in my game. It should be much easier than P2P. Now here is the problem:
Suppose, I have 1 server and some clients (may be 1 or more clients). They all should give the following output:
Starting... A B C E F ... ... Done!
They all give the above output without using multi-thread. But using multi-threading, it gives the above output only when there're 1 server and 1 client. I'm using 2 threads (1 for sending, 1 for receiving) for each Socket. That means, each client has only 2 threads for communication but the server has (2 * totalClients) threads.
I've attached my full test project. So, here I'm only showing my 2 thread classes.
ReceiveThread class: class ReceiveThread extends Thread { private ObjectInputStream receiveStream; private BlockingQueue<Character> queue = new ArrayBlockingQueue<Character>(Common.totalClients);
[Code] ....
Since I've attached my full test project, I'm not showing the other 3 classes. They are ServerMain, ClientMain and Common. If I've 2 clients to be connected, then I get the following output:
Server: (Runs first)
Starting... A Client 1 (clientID is 1): (Runs after the server)
Starting... A B B Client 2 (clientID is 2): (Runs after Client 1)
Starting... A
They are stuck at there, even no exception. Actually, the server and the clients are stuck at the line try { ch = queue.take(); } if more than 1 client are connected. It seems that all are trying to receive data. But without using the dedicated threads, they all work as expected even for more than 1 client. Why is this behaviour? How to solve it? Note that I have used the same SendThread and ReceiveThread classes by which I have succcessfully implemented P2P communication.
About my attached test project file:
It has 5 small .java files for the classes as stated above. It is currently faulty when using additional threads. You have to change clientID variable for each client (they are described inside). But it works as expected without additional threads. To test it without the additional threads:
Comment " TODO" linesUncomment the single lines just after " TODO" linesComment the additional thread construction lines (4 lines)
Currently, for a workaround, I'm not using the dedicated threads for sending and receiving data only for client-server communication in my multi-player game. But I'm still using these threads for P2P communication. I don't know why it is and how to solve it.This is the attached test project file as described above.
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'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 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.
So we have a Client and Server. Client opens a socket to Server, server initiates new Thread to handle the communication with client. Is there a way to be singnalled when there is input on socket, so I don't have to use infinite while loop solution?
Any example of client/server socket based application using Spring and Maven where application do the following
Client sends a request with a path to any file on the server „h Server reads the file and responds back with the content „h Client outputs the content to the console
Now I played a little with EJB3. I want to start a timer bean in a 10second interval which retrieves the IP of registered devices from a databases, opens client sockets with a Thread Pool and retrieves the XML file over HTTP GET of each device listed in the db.
Is it possbile with EJB3? how to start thread based background services like that within EJB3 timer bean?
I've just recently started playing around with network programming in Java, and I've come up with a simplistic server than can handle multiple clients and return the IP and port each one is connected to (or I'm under the impression that is so). What I've been requested to do as an exercise by one of the programming teachers at my high school (I'm not in a class, this is my own time) is send a message from one client to the other through the ServerSocket so that it may "watch" everything going on. I'm not sure how to go about this at all.
EDIT : now it never seems to go the the else or else if statements...
That is now the main problem. It never, ever, goes past the first if statement, no matter what it is.
EDIT : Okay, I haven't changed a line of code but suddenly not a single if statement is working. They just stopped. The client simply hangs and I can't type anything.
Server
public class Server implements Runnable { Socket clientSocket; Server(Socket clientSocket) { this.clientSocket = clientSocket; } public static void main(String args[]) throws Exception { ServerSocket ssock = new ServerSocket(3480); System.out.println("Listening on port 3480");
I write a Client/Server program,trying to send and receive a object between client and server. I use the ObjectStream but there exists an EOFException on the client side when invoking readObject() .... I've tried many times but couldn't figure it out ...
server-side code
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try{ ObjectOutputStream out = new ObjectOutputStream(resp.getOutputStream()); ObjectInputStream in = new ObjectInputStream(req.getInputStream()); PersonalData pe = (PersonalData)in.readObject(); System.out.println(pe.getYearlySalary());
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 am trying to check the integrity in a Bank Transaction that the message sent to the server has not been modified by any malware in the client system. For this I am trying to read the message sent to the server at the client boundary so as that it enters the network as customer with customer intended values. So, firstly I need to check where to I need intercept the message within client boundary. Secondly, Can I intercept the message and read its contents using Java?
I want to check what my Online Banking Server( Leta Say Bank of America) receives if I ask to transfer amount $100 to Account A . I assume that there is a malware in client system that changes recipient to B,$10000. My aplicaion which I intend to design, shoudl inform the user that the integrity of the message is compromised and should give the option to the user to abort it. plan to track what message is being sent from client to server. This I want to achieve by reading the message from client at the last point before it leaves the client and enter the network.
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.
I just want to add a text field and a label next to it that says "Hourly Wage".
Also, when I run this in Xcode, it reports back with "Shell Script Invocation Error" "Command usr/bin/java failed with exit code 1".
Here's my program:
package summerIncome; import java.util.Scanner; public class SummerIncomeCalculator { public static void main(String[] args) { jFrame frame = new Jframe("Summer Income Calculator"); frame.setSize(400,300);
I have tried each and every thing in all the other answers. Like setting chunked to false, changing parameters, changing http1.1 -1.0. I am just writing a sample client to compare it with my real time client. Following is the code of client:
package com.webservicemart.ws; import java.rmi.RemoteException; import org.apache.axis2.AxisFault; import com.webservicemart.ws.USZipStub.ValidateZip; public class UsZipClient { public static void main(String[] args) {
[Code] ....
And Following is the error :
[INFO] Unable to sendViaPost to url[http://www.webservicemart.com/uszip.asmx] org.apache.axis2.AxisFault: Transport error: 404 Error: Not Found at org.apache.axis2.transport.http.HTTPSender.handleResponse(HTTPSender.java:310) at org.apache.axis2.transport.http.HTTPSender.sendViaPost(HTTPSender.java:194) at org.apache.axis2.transport.http.HTTPSender.send(HTTPSender.java:75)
[Code] ....
I have tried with other geoIP service and weather forecast too. I get the same error.