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
The problem is that I often receive ArrayOutOfBound errors when I try to parse the byte array. I think that I'm reading from the socket in a wrong way..
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 wanted to take strings in from the user through a GUI say day, month, year. I am looking for a way to organize those incoming strings. I am going to add this information to a queue. However, I want the people who put in the earliest day, month, and year to be put into the queue first followed by the next earliest so on and so forth.I was thinking what I would need to make a method that would compare the information.
I am attempting to make a twitchplays bot but, I cannot get the bot to join my channel.
public class main { public static void main(String[] args) throws Exception { Twitchbot bot = new Twitchbot(); bot.setVerbose(true); bot.connect("irc.twitch.tv", "6667", "oauth:734gln7txe9u0546a0fmdlkw95hcr9"); bot.joinChannel("#donnie64"); while(true) { //this code will be looped } } }
This is my main code, without the loop it gets terminated automatically. The console is blank after running the program.
I am using a static initialization block to register the driver and a static synchronized method to get a connection. The problem is I need to run 15 threads but always only two threads get the connection. I want to know if there is a default maximum number of concurrent connections a DriverManager can provide or is it my threading logic that may be faulty.
In the class that actually uses it I create a method variable for the connection object.
Closing the connection as well as pds.getConnection().close();e
I am thinking that at the most I should have only one inactive connection showing up when I monitor the session. How do I configure the pool as to only show on inactive connection? I am running the test queries once every five minutes. But I am opening three connections each time.
This is my code, I copied it from [URL]. I am trying to use it to extract news from news channel websites.
I used the following URLs: [URL]
//------------------------------------------------------------// // JavaGetUrl.java: // //------------------------------------------------------------// // A Java program that demonstrates a procedure that can be // // used to download the contents of a specified URL. // //------------------------------------------------------------//
[Code]....
Also, when I try a local server URL, the output screen goes blank, which I guess is due to lack of Text on the local URL. So, the little research that I did, made me believe that the code not running on external server was due to firewall on the server side. How to run it. Also : I work on a proxy network.( if that has something to do with this).
displaying COM port in Combo box , see my code below , it does not show any error but it does not show COM port in combo box , instead it shows the class name of Communicator with some garbage data .
I have created a java gui application and I need to communicate through the serial port. I would like to open the serial port in the beginning of the application and then close it when the applications closes. The problem that I am having is that I created a method to open the serial port in the main function but I can not close the serial port on exit off the application. Is there away of having the serial port be setup so that all methods can access the serial port.
I'm a new in java program. I need reading COM port on GPRS Modem. I plug the GPRS Modem in my PC and it has connected. I use Eclipse and create a project and new a file a.java, i collect this following code from the internet and paste it into the a.java file.
Java Code:
package serial; import java.io.*; import java.util.*; import javax.comm.*; //for accessing serialport public class OwnPort { static CommPortIdentifier portId;
[Code] ....
You can see the result here
I don't know the result why return " Set default port to COM4. port COM4 not found."
My company is a transport company. We receive goods form partner and transport it to customers. There is a process that we must accept a number of kilograms into bill after we weigh goods by the electronic balance(the electronic balance have serial port plug in PC) . To decrease this process, I'm looking for a project "read serial port wrote in java applet". Who have code,
I am trying to connect to Sql Server database using Oracle UCP with sqljdbc4-3.0 JDBC driver for Sql Server,with different ports and instances.
– the issue is with the port being ignored in the server string.
For example, using port 1440 connects to the default instance (which is on port 1433) rather than MSSQLINSTANCE1 which is on 1440.
Below are Server hosts used.
sql005.sqlasoftware.com (connects correctly to the default instance) sql005.sqlasoftware.com:1440 (connects incorrectly to the default instance on port 1433) sql005.sqlasoftware.comMSSQLINSTANCE1 (connects correctly to the named instance)
I need to port asynchronous bean (provided by websphere) support in App servers like weblogic and jboss. Is this feature already part of J2EE specification? Or should I use some other external package to get this feature?If so what are those async bean like features for weblogic and jboss?
A wages calculator application is required that can determine the total cost of crew departing from the port on that day. To do this, the application reads from an itinerary text file containing each ship being loaded in the port that day, in the following format:
<ship id> <journey id> <l> // where <l> is the length in hours of the journey <s> // where <s> is the number of crew for the ship for this journey <rate> // for each s, <rate> is hourly rate of pay
Your application must calculate the total cost of the crew for each ship/journey and then compare it with a "recommended maximum journey cost" (RM) amount typed in by the user when the application is first run. If the total amount is less than or equal to RM then the details must be written to the screen and to an output text file called wagedaily.txt. If the amount is larger than RM then the results must be written to the screen only. Messages to the screen must indicate whether the crew cost is less than, equal to or larger than RM.
Your application should find the ship with the highest crew cost that is below RM and print this out as the final piece of output to the screen.
It has given me a bunch of ships and numbers to play around with in the code, here they are:
I am developing a web application using JSF-2.0 on weblogic 10.3.6. I am using Facelets as VDL. I have 5 different machine. They are different according to their OS and their geographical location. On my first xhtml page server (machine) is decided. Then on next page file upload and rest of processing takes place. My restriction is that SSO configuration can be done on only one machine.
So I am restricted to using xhtml files from only my primary server where SSO configuration is done. But I have to connect to servlets or managed-bean of different machine as requests are machine specific and file needs to be uploaded to those machines for processing. So I cannot use redirectUrl as I need to be only on one machine. Is it possible that xhtml on one server can talk to managed-bean on other server(different machine)?.
I am working on a chess game. I need to construct a game room where all the player are present and room chat is up. Also some tables where games are being played. Now my question is how to create this game room?
To me this room must need to be like static or global (if I am not mistaken) that is up when server starts and players can join this room and should be down when server is done. How can I implement such room that would stay up for infinite time.
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 ?