Server / Multi Clients

Mar 9, 2014

I have made a server/multi Clients where Clients send Double data but my problem is that the clients send this data to Server only wonce, and the server waits again the connection from client. (I have to run the clients manually each time)what i'm looking: the client should always send data to server. like an infinite loop.

View Replies


ADVERTISEMENT

Create A Server Which Sends Clients Connected To It Its Local Time

Apr 5, 2015

I'm trying to create a server which sends the clients connected to it its local time. Looking at a few tutorials I've managed to connect the clients to the server, but can't send data to the clients. I've successfully done easier examples, without threading. I guess the problem might be im me not knowing what exceptions are for.

Client: When running the code "AAAAAAA" does execute but "BBBB" doesn't, so I guess the problem should be in fraseRecibida = entradaDesdeServidor.readLine();

import java.io.*;
import java.net.*;
import java.util.Scanner;
public class Client {
public static void main(String[] args) throws Exception{
String fraseRecibida;

[code]....

I don't understand the exceptions, maybe I should give them a look before continuing with sockets. Being frank I'm not really sure why the while(true) is there.

import java.io.*;
import java.net.*;
import java.util.Calendar;
public class ServerThread extends Thread{
Socket socket;
ServerThread(Socket socket){
this.socket = socket;

[code].....

View Replies View Related

Java Socket - Client-server Communication Stuck With Multi-threading

Feb 6, 2015

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.

Attached File(s) : Test Project.zip (4.11K)

View Replies View Related

Start Client Actions Only Once All Clients Connected

Aug 30, 2014

I was tasked to do a 2-4 player network card game. Before I jumped into doing the card game. I decided to try out an a simple program which is the clients taking turns to type in their textfield.

I have a server that listens to 3 incoming client connections. once all 3 clients is being connected,

Steps

1) The first client will send the message first while the second and third client will wait for the first client to finish sending.

2) After the first client finished sending the message, it will be second client turn to send the message and the third client will wait for the second client to send finish.

3) After the third client finished sending the message, it will be third client turn to send the message and the first client will wait for the third client to send finish and (go back to step 1))

**The first client can only start typing once all 3 clients is being connected**

In my server class,I spawn a new Thread once a client is connected, I do a wait() on each time the client is being connected, I stored the thread in a arraylist as well. I have an id to keep track how many clients is currently connected. once the id reaches 3, I used notifyall() to notify all the threads and set the first position of my arraylist as my currentThread so that I can keep track which is the currentThread running.

I started 3 clients. and I typed the textfield of the first client but my server isn't receiving any messages.

class Server implements Runnable {
private List<SpawnNewThread> sntList = new ArrayList<SpawnNewThread>();
private SpawnNewThread currentThread;
private int id = 0;

[Code].....

View Replies View Related

How To Receive Some Data From Multiple Clients On Network

Apr 16, 2014

I got my first project in which i need to receive some data from multiple client on network regularly(say every second) and then process that data and stored it to the database and then GUI needs to be created which display data accordingly.

While thinking for the design i thought blocking queue to implement the same. Like producer receive data from the port into a string builder and put that into the LinkedBlockingQueue. Consumer will take this data , process some work on it and store it into the database.I am using sybase ase 15 as a database.

My question is as i am receiving data very frequently which require insertion , updation and search almost every second into the database. What is the best way to improve the performance.

say i have 2 types of data is coming one having keyword 'Alarm' and other having 'ceased' so i need to use something like this

common fields in both is name and number.

if (ceased)
search into the database for particular event for which this ceased receive using name and numbe rand update the another field into it Also make separate entry for it
else
make a entry

Also as i am using 2-3 thread for consumers and thread = Number of client for the producer. So i thought to use synchronization at the consumer side which writes data into the database such that only 1 thread can write it.

View Replies View Related

Java Database System - App For Nutritionists To Check What Their Clients Are Eating

Oct 23, 2014

I've been asked to create an app for nutritionists to check what their clients are eating.

I've found a database of all foods with nutritional values. In the past I've dealt with databases which just have are just one dimensional, so it's been easy to just create a string array for it. But this is absolutely huge, it's got about 10,000 rows and 30 or so columns, so that's not going to work any more.

The app needs to ask what the client ate at which times, and then save this along with the nutritional values.

What would be the best way to go about storing and calling a database of this size in java?

Should I learn SQL and JDBC to tackle it or is there any easier way?

View Replies View Related

JSF :: XHTML On One Server Can Talk To Managed-bean On Other Server (different Machine)?

Jul 27, 2014

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)?.

View Replies View Related

Servlets :: How To Create A Room That Should Be Like Static On The Server Until Server Is Down

Apr 1, 2014

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.

View Replies View Related

Multi-Array Of JButtons

May 18, 2014

Java Code:

import java.awt.Color;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class Screen implements ActionListener {
public JButton[][] b=new JButton[200][200];

[Code] ....

I am trying to create the A* Algorithm and I REALLY need a 2D array to handle this.

This is the error:

Java Code:

at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162) mh_sh_highlight_all('java');

View Replies View Related

Multi Array Of Buttons?

May 18, 2014

import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

[Code]....

I am trying to program an A* algorithm and I cannot even get past the buttons. I need a 2D array of buttons to handle this problem but I am getting the following errors.

at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)
at java.awt.AWTEventMulticaster.componentShown(AWTEventMulticaster.java:162)

[Code] ....

View Replies View Related

Servlets :: Multi Threading Mechanism?

Nov 16, 2014

Is there any specific name for servlet's multi threading mechanism? I mean any technical term for it.

View Replies View Related

Java UDP Sockets And Multi-Threading

Dec 26, 2014

I have been practicing writing java code, my university course is going to cover socket programming and multi-threading.

I am presently just starting to write myself a framework for all multiplayer games I may make in the future, my aim really is simply to practice and understand better and this time, im not using an ide, just sublime text, all new grounds for me, I have a good basic understanding of the subject but I want to be fluent.

import java.net.*;
import java.util.ArrayList;
import java.io.*;
/*SMOOTH THREAD SAFE MULTI CLIENT HANDLING CLASS.
*
*This class will create connection objects when a connection is detected, these connections will run in a separate thread and update an array list in their parent class containing their last sent data

[Code] .....

View Replies View Related

Multi-dimension Array Declaration And Instantiation?

May 17, 2015

Whilst pre-preparing for java certification, one of the online mock exams has slightly confused me by saying my answer was incorrect for multi-dimension array 'declaration and instantiation'.

This is one of the answers i chose - which was marked as incorrect

a)
int[][] array2d = {{123}, {4,5}};

Which looks absolutely fine to me.One of the other answers, which i agree is correct and so does the mock exam is

b)
int [][] array2d = new int[2][2];

View Replies View Related

Calling Multi-Threading With For Loop - Error

Feb 2, 2015

I have a problem with multi threading calling with for loop. I have those two and many other classes in one jar file but n 2 different packages.

When i execute the jar file first runs the Aclass, from where i try to run multi threads. From the run() of the class RunTheGame i call many other classes which are in the same package. Like you can see from the for loop is executed the threads.

The problem is that when the second thread starts the first one is stopped this happens for all the threads, more simply when a new thread starts the old one is dead.

It seems that liken the threads uses the classes called from run() of the class RunTheGame as non multi threaded. It gives this error:

Java Code:

Exception in thread "Thread-0" java.lang.NullPointerException
at thePackage2.EClass.getWhiteRemaining(EClass.java:49)
at thePackage2.EClass.isFinal(DClass.java:84)
at thePackage2.Spiel.<init>(Cclass.java:76)
at thePackage2.RunTheGame.run(RunTheGame.java:198)
at java.lang.Thread.run(Thread.java:745) mh_sh_highlight_all('java');

All the above refereed classes are called from the from run() of the class RunTheGame . Like i understand all the threads use those classes as non thread autonomous classes.

Java Code:

public class Aclass {
private static Thread t[];
public static void main(String[] args) throws IOException {
for (int Game = 0; Game< 10; Game++) {
t[Game] = new Thread(new thePackage2.RunTheGame(aplayer, bplayer, Name, ID , Pmach));
t[Game].start();

[Code] .....

View Replies View Related

Multi-User Console Chat Program

Nov 22, 2014

My task is to create multiuser console chat program. During whole day of poking around , i finally stand on such concept:

1. When running , Server part must stay into while(true) loop and create threads on each ServerSocket.accept() call, providing socket object inside thread. i.e.

while (true){
System.out.println("Waiting for client to connect");
Thread t = new Thread(new Runner(servSocket.accept(),listOfClientSockets));
System.out.println("Starting thread");
t.start();
}

2. Client side always stays within while(true) loop and waiting for user input with ScannerInstance.nextLine() method.
As soon as user prints something and hits enter, data being captured from scanner and thrown to socket output stream to the server.

My question is : if all parties (X clients and server) are actually in waiting mode (server is waiting for connections and each client is waiting for user input), who will refresh the screen for each client to draw the messages other parties sent?

At this time , each party see updates only when he hits enter and while loop does next iteration reading data from buffer and displaying on console.

View Replies View Related

Consumer / Producer Multi Threading Scenario

Jul 9, 2014

Just some questions regarding a Consumer producer program I am not understanding. Here are the two classes Below and my questions are :

1. In the main method for NamedConsumer, we created an instance of the class and call it "consumer" and we start it. Then we create another instance and we give its reference to the same variable. Doesn't this in turn destroy the original reference of the first instance we created which was started? Could we have done

NamedConsumer consumer1 = new NamedConsumer( "One", producer );
new Thread( consumer1 ).start();
NamedConsumer consumer2 = new NamedConsumer( "Two", producer );
new Thread( consumer2 ).start();

2. we called start on two difference instances of the NameConsumer class. Doesn't the "run" method need to be synchronized since two threads are hitting it?

Producer.Java

Java Code: public class Producer implements Runnable
{
static final int MAXQUEUE = 5;
private List<String> messages = new ArrayList<String>();

public void run() {
while ( true ) {
putMessage();
try {
Thread.sleep( 1000 );

[code]...

View Replies View Related

How To Access Element Of Multi Dimensional Int Array Using For Loop

Jul 12, 2014

I have written following code.

I want to print all elements in Array to output here is my code

int[][] arr={{12,12,13},
{14,1223,14}};
for(int i=0;i<arr.length;i++)
{
for(int j=0;j<arr.length;j++)
{
System.out.println(arr[i][j]);
}
}

but I am getting following output

12
12
14
1223

how to print all elements of int array?

View Replies View Related

Multi-Threading - Unable To Get Outputs But Many NPEs Error

Feb 14, 2014

I have been trying for days and nights , no compile error , but alot of NPEs error .......

This is my Test program

import java.util.*;
public class Test
{
public static void main (String[]args)
{
int totalShares = 0 ;
double totalCost = 0.0;
double totalProfitLoss = 0.0;

[Code] ....

I am expecting a output like this (Which I have error running:

Tracking of Stock : FCS
8 shares has been brought at $37.61
Total shares now 8 at total cost $300.88
33 shares has been brought at $36.31
Total shares now 41 at total cost $1499.11
17 shares has been sold at $42.67
Total shares now 24 at total cost $773.72
19 shares has been sold at $32.31
Total shares now 5 at total cost $159.83
31 shares has been brought at $33.85
Total shares now 36 at total cost $1209.18
28 shares has been brought at $36.37
Total shares now 64 at total cost $2227.54
20 shares has been brought at $35.49
Total shares now 84 at total cost $2937.34
At $36.00 per share, profit is $86.66

View Replies View Related

JavaFX 2.0 :: Create List Of Entities - Multi-row Tableview?

Apr 10, 2015

I would like to create list of entities which is populated by a search function with the data coming from our REST webservice. However I would like it to be multi-line, with the first line being details from the entity itself and the second line buttons for options that can be performed.
 
So as an example say my entity is People, the first line would contain columns for first name, last name, gender, DOB, etc. The second line would be buttons for "Edit Person", "Print Person details".   With the standard TableView I can't see anyway to alternate between one row of data and another row of buttons.

View Replies View Related

Multi-Player Game With Multiple Worlds - Unhandled Packets

Sep 16, 2014

So I am trying to create a Multi-Player game in java, and I have a Game server and a Client. They normally connect with either but I would like to add a login server so that there can be an option to go to a different world then just the main one. It will have the same map and data but will be separate from the Players that are on world one per say. Now if you are on world two I would like it to have the option for you to be able to Private message players that are on World one. That is where the login server comes in to play.

I am still new at Java and would like to be able to understand Packets and how to handle them more clearly. So far I have gotten the basis of the login server connected to the server and the client connects to the server via the login server. But I am getting a bunch of "unhandled packets" and I would like to know how to handle them. Here are some bits of the code.

package com.ls.net;
import org.jboss.netty.channel.ChannelHandlerContext;
import org.jboss.netty.channel.ChannelStateEvent;
import org.jboss.netty.channel.ExceptionEvent;
import org.jboss.netty.channel.MessageEvent;
import org.jboss.netty.channel.SimpleChannelUpstreamHandler;

[Code] ....

So when I run my client this pops up in the console:

[Tue Sep 16 16:50:56 EDT 2014][LoginServer]: Finished initializing login server.
[Tue Sep 16 16:50:56 EDT 2014][SignalMultiplexer]: Unhandled packet: 15
[Tue Sep 16 16:50:56 EDT 2014][SignalMultiplexer]: Unhandled packet: 41
[Tue Sep 16 16:50:56 EDT 2014][SignalMultiplexer]: Unhandled packet: 74

[Code] ....

And here are the class's for Accounts:

package com.ls.net.codec.decoder.packets;
import org.jboss.netty.buffer.ChannelBuffer;
import org.jboss.netty.channel.ChannelHandlerContext;
import com.ls.bufutils.BufferUtils;
import com.ls.net.codec.decoder.PacketDecoder;
import com.ls.net.codec.decoder.handlers.AccountHandler;

[Code] ....

View Replies View Related

Multi-word Hangman Game - Spaces Not Displayed When Program Run

Apr 9, 2015

I created a simple Hangman game. It functions correctly, the only issue is when the file contains a phrase (2 or more words), spaces are not displayed when the program is run. For example, if the phrase was Java Programming Forums.

It would appear as _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _.

I want there to be spaces in between the words. How could I fix this? What would I need to add to my code?

import java.util.Scanner;
import java.io.*;
 public class hangman{
public static void main (String[] args) throws FileNotFoundException{
Scanner kb = new Scanner(System.in);
String guess;
String guesses = "";
int wrongGuess = 8;

[Code] ....

View Replies View Related

Connect A UDP Web Server To Compression Server

Apr 19, 2015

Working on a project and am in need of some quick guidance to wrap things up. I have a functioning compression server that will create two files after the user gives it some input and a "magic string" to know when to stop reading input for that specific file.

I now need to connect a UDP web server to that compression server. the web server will read from the HTTP POST Request the data that was uploaded and send it to the compression server to create the two files... i have included both programs below

Web Server:

import java.io.*;
import java.net.*;
import java.util.*;
final class HttpRequest implements Runnable {
//Declare Constants and Variables
final static int BUF_SIZE = 1024000;
final static String CRLF = "
";

[Code]...

Compression Server:

import java.net.*; // for DatagramSocket, DatagramPacket, and InetAddress
import java.io.*; // for IOException
import java.util.zip.*;// for Zip
public class CompressionServer {
private static final int ECHOMAX = 65535; // Maximum size of echo datagram
private static final int BUFFER = 2048; // Buffer size for writing to Zip File

[Code]....

View Replies View Related

Connect Four Game With Java Swing / Make Multi D Panel Maker When Try To Run It

May 31, 2014

I am trying to make a Connect Four game with java swing, but I am getting an error with my attempt at making an multi D panel maker when I try to run it.

import javax.swing.*;
import java.awt.Color;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
 
[code]...

View Replies View Related

JavaFX 2.0 :: How To Create Off Screen Images By Canvas In Multi-thread Environment

Feb 25, 2015

I want to create off-screen images by Canvases in multi-thread environment.
 
I know that I use methods of GraphicsContext2D to draw on Canvas. Can I do this on Canvas which is not added to Scene ?
 
How can I get an image from a canvas after I invoke GraphicsContext2D methods? Can I get images in multi-thread environment ?

View Replies View Related

Could Program Fail With Race Condition By Concurrent Threads In A Multi Thread Environment

Feb 18, 2014

I have a task of returning US holiday based on the given date and this utility will be used in a multi thread environment. I have written as below, how to know if my code breaks at any given point by multiple threads

Declared Enum

public enum Holiday {
CHRISTMASDAY("Christmas Day"),
GOODFRIDAY("Good Friday"),
INDEPENDENCEDAY("Independence Day"),
LABORDAY("Labor Day"),
NONE("None");

[code]...

I tried to test this with few concurrent threads, and noticed that the DB call is made for the very first time or when the year being requested is not same as the cached year. But I wanted to see, if this is properly synchronizing and would not fail in any case. My intention is to make a singleton HolidayCalendar, and also synchronized well enough so that every thread using this class gets the required data without blocking each other.

View Replies View Related

I/O / Streams :: Find Line Number In A File Using Multi Line String

May 5, 2014

My requirement is to find the line number using multiline string. Here I need to extract the string between FROM and where clause(from the below string) and need to find the line number in the file

SELECT HL.LOCATION_ID,HPS.PARTY_SITE_ID,HCAS.CUST_ACCT_SITE_ID
INTO LN_SITE_LOCATION_ID,LN_LOC_PARTY_SITE_ID,LN_CUST_ACCT_SITE_ID
FROM HZ_LOCATIONS HL,
HZ_PARTY_SITES HPS,

[Code]....

View Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved