Synchronize UDP Sending And Receiving

Apr 16, 2015

Say I was to make a computer game, the first person to play the game would have a joinable game and would then be the server, and anyone joining in would be the client and the server was updated with JSON data of the clients computer game, and the server would then update each client of each characters new data using JSON, I would need fast multi threaded connection handling with minimum overhead, Is there a specific way to do this? or are there many?

I have realized there are a few ways to send and receive data using UDP and while experimenting I have also found its quite hard to synchronise.

Do I have a connection listening until there is data to be sent and then switched back to listening?

Do I have the server listening for a microsecond and then checking to see of there's anything to send for a microsecond continuously?

Do I have multiple connections for sending and receiving

Do I create new connections for each new and individual packets to be sent and received dynamically on a thread?

What is the optimum most effective way and do my examples reflect much understanding at all? my resent attempts create new problems and rather than re invent the wheel I would like to know what is normally done.

View Replies


ADVERTISEMENT

Sending To All Vs Sending To One Person In Server / Client Program

Apr 17, 2014

I have two programs that I'll post below, one is a Server and the other is a Client. The ChatServer runs once and many clients can run ChatClient from separate computers and talk together in their GUI's. The the client program comes with two buttons, one that's simulates the sending of a message to a single user ; "Send Message To User", and one that just generally sends a message ; "Send Message To All". Although now the Clients on the server seem to be able to selectively send messages to an individual by giving the recipient name, all the clients can see that message, which is not exact what I am aiming for. What I am going for is having the "Send Message To User" button click to send a message to the named user without all other users seeing the message.

The Server Program Code

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.ArrayList;

[Code] ....

Now I have tried thing like having various input output streams and trying to connect those, but no luck. Tried fiddling with having the names arraylist directing the messages to one client versus all but that did not work out either. How I what I would need to do to go about doing this?

View Replies View Related

EJB / EE :: When Timer Data In Cache Is Updated On One Server / How To Make It Synchronize To Other Servers

Oct 31, 2014

Our company has a web based project which using the Jboss EAP 6.1 +EJB 3.1 + JSF2 and deployed it in a cluster environment(Server A,Server B and Server C).We have created some schedule tasks by using EJB timer service and the timer data file is stored in a central file system.And users can login and access to a task configuration page to customise his own tasks by create,update,delete actions etc.But we find that the timers don't work correctly in the cluster environment.

For example.When we start the Servers(A,B,C),each server will load the timer file data into his own node cache from the central file system.But when one user go to the task configuration page to update or delete his own tasks from one of the Servers, it only update the change on its own node cache and don't replicate the timer data to other nodes' cache and which cause the problem.

I know there is one way to fix it is that we could shutdown the three Servers and re-boot them and the timer data file will be re-loaded into each server's cache. But we can't do that because the users want their own created/updated tasks take effect immediately once they change them.My question is that when the timer data in cache is updated on one server, how to make it synchronize to the other Servers'.

View Replies View Related

JavaFX 2.0 :: Synchronize Model Representing Complex UI Composite With FlowPane Backing List

Aug 26, 2014

What is the best way to synchronize a Model representing a complex UI composite w/ a FlowPane's backing list?
 
Currently I have a change listener on the Model.  Upon an add I create a new UI composite and manually add it to the FlowPane's backing list via flowPane.getChildren().add().  Similarly if there is a remove, I iterate over the FlowPane's children, grab the right Node, and remove it.  Similarly, if there is a modification detected, I iterate over the FlowPane's children, grab the right Node, remove it, recreate the UI composite, and re-add it to the list.  I also need the list to be sorted, so I implemented a UIComposite comparator and call FXCollections.sort() on the FlowPane's backing list.  I feel like that is hacky, but it works.  It would be cool if I could maintain sort order in my model somehow and have that automatically propogated to the FlowPane's list.
 
I am correct in assuming that there is no way to have a complex binding in between an ObservableList<CompositeViewModel> and the FlowPane's backing list (ObservableList<T>)? 

Some kind of translator that could create a new UIComposite whenever there is a new CompositeViewModel added to the Model list.

View Replies View Related

Receiving ParseException With String

Aug 28, 2014

Keep getting a ParseException when I try to parse a ISO 8601 formatted String into a Java Date type.

String myDateString = "2014-07-04T22:59:36Z";
TimeZone timeZone = TimeZone.getTimeZone("UTC");
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm'Z'", Locale.US);
dateFormat.setTimeZone(timeZone);
Date formattedDate = dateFormat.parse(myDateString);

Keeps returning a ParseException:

Unparseable date: "2014-07-04T22:59:36Z"

What am I possibly doing wrong?

View Replies View Related

UDP Packet Not Receiving While Using Multicasting In Java

Jan 21, 2014

import java.net.*;
public class SendConfig {
InetAddress SYSTEM_IP;
int SYSTEM_PORT = 5000;
InetAddress MULTICAST_IP;
int PORT = 6000;

[Code] .....

View Replies View Related

Keep Receiving Unreachable Statement For Code

Nov 27, 2014

public String toString()
{
return questionText + "
";
char label = 'a';
for(int i= 0; i < answers.length; i++)
{
return "("+label+")"+" "+answers[i]+ "
";
label++;
}
}

I keep receiving the unreachable statement for line 4. I don't know why?

View Replies View Related

DatagramChannel - UDP Receiving OK / Unable To Send Data

Apr 29, 2014

I am trying to connect to a local service over UDP - the simulator works fine, but my code does not... The sender is a separate thread and I have tried blocking, non-blocking, connecting, not connection, reading and re-reading the Oracle docs,

Java Code:

package my.comm;

import my.myMethods;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

[code]....

View Replies View Related

Not Receiving Correctly SMS Over Length Of More Than A Page Using AT Command

May 10, 2014

I am working on the SMS receiving using AT Commands using JAVA. i m getting the message of one page correctly using AT commands, but as i increase the size of SMS as 2, 3 or bigger pages the alphabets are converted to some thing like this

+CMGL: 0,"REC UNREAD","+923028910082",,"14/05/10,19:32:40+20"
4469616C202A3334352A393333232061757220536972662052 732E3230206D65696E20332064696E206B6120696E7465726E 65742028333030204D422920686173696C206B6172656E2120 7777772E776170747269636B2E636F6D2070657220736F6E67 73206175722067616D657320656E6A6F79206B6172656E2120 42616C616E636520636865636B206B206C7965202A39393923 206D69

Whats the problem I am not getting the right text which i have sent through my mobile phone.my function of receiving SMS is as follows :

public void send(String cmd) {
try {
outputStream.write(cmd.getBytes());

} catch (IOException e) {

[code]....

View Replies View Related

I/O / Streams :: Not Receiving Correctly SMS Over Length Of More Than A Page Using AT Commands?

May 10, 2014

i m working on the SMS receiving using AT Commands using JAVA. i m getting the message of one page correctly using AT commands, but as i increase the size of SMS as 2, 3 or bigger pages the alphabets are converted to some thing like this

+CMGL: 0,"REC UNREAD","+923028910082",,"14/05/10,19:32:40+20"
4469616C202A3334352A393333232061757220536972662052732E3230206D65696E2
0332064696E206B6120696E7465726E65742028333030204D422920686173696C206B
6172656E21207777772E776170747269636B2E636F6D2070657220736F6E6773206175
722067616D657320656E6A6F79206B6172656E212042616C616E636520636865636B2
06B206C7965202A39393923206D69

Whats the problem i m not getting the right text which i have sent through my mobile phone.

My function of receiving SMS is as follows :

public void send(String cmd) {
try {
outputStream.write(cmd.getBytes());
} catch (IOException e) {
e.printStackTrace();

[Code] .....

View Replies View Related

Simple Mathematical Computation Not Working - Receiving Errors

May 3, 2015

Here's my code:

System.out.println((3 / 1.5) + 42(3 + 3));

I don't understand what I'm doing wrong. I'm receiving these errors:

PrintFunction.java:8: error: ')' expected
System.out.println((3 / 1.5) + 42(3 + 3));
^
PrintFunction.java:8: error: not a statement
System.out.println((3 / 1.5) + 42(3 + 3));
^
PrintFunction.java:8: error: ';' expected
System.out.println((3 / 1.5) + 42(3 + 3));

I'm using Sublime Text and JDK 8.

View Replies View Related

Receiving Wrong Minimum Value And Code Is Not Reading File Properly

Feb 11, 2015

My program is reading my file, but its printing out weird cryptic numbers instead of the 1-10 that is in the file. But it uses the numbers in the file to get the Max Value and Total. Also I am receiving 0 for my Minimum Value but, 0 isn't even in the file, my lowest value is 1.

Java Code: /*

* Student Name: Irrelavent
*
* Description: This program will read from a text file and display its contents in an array format as well as the average of the numbers and the minimum and maximum value within the array and it will display the total of all the numbers added together.
*
* Input Variables:
*
* Desired Output:
* Total: 55
Average: 5.5
Minimum Value: 1.0
Maximum Value: 10.0
The data being used is: [1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0]
*/

[Code] ....

Output:

Numbers being used: [[I@55f96302]

---------------
Max Value: 10
---------------
Minimum Value: 0
---------------
Average: 0.0
---------------
Total: 55

I want 1 for my Minimum and I want 5.5 for my average, when I make 'average = total / numbers.length;' ---> 'average = total / (double)numbers.length;' I get 0.55. Also, as its obvious, my 'Numbers being used' section is messed up and I don't know whats causing this.

View Replies View Related

Methods From Original Class Receiving Error When In Test Class

Jul 5, 2014

I am working on a program that simulates a bug moving along a horizontal line, My code works correctly when I test it in it's own class but when I tried testing my constructor and methods in a test class I received an error saying, "package stinkBug does not exist" on lines with my methods. However, stinkbug is not a package.

Java Code:

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/

[code]....

View Replies View Related

Sending XML To PHP Service Via POST

Jul 7, 2014

I have a server with a handful of php services. I communicate with these services by creating connections from java code. The services currently respond with XML, but that can be changed if an alternative way can improve performance.

One of the things I need to do is send varying sized payload (some large) to one of the services. My current plan is to create an xml file in java and perform a POST request with the XML as the payload. I am using an XML because the data is very structured.

From a performance point of view, would it be better to send the XML as a file or just as text? Also, is there a better way to send this data? These services will eventually be used by an android app, where performance and minimizing the size of the data packages will be extremely important.

View Replies View Related

Sending Two Strings Into A Constructor

Jun 13, 2014

I did this using ArrayList<String> and my tests worked. Meaning I was able to read the strings in a different class through my constructor. However I want to use a string array because it will be easier to handle when I finish the program. I will send each players poker hand in and figure out who is the winner instead of putting it all onto a ArrayList and having to iterate through it. However whenever I did my check I am just printing null.

PokerFile class

void separateHands(String cards) {
//ArrayList<String>playerOne = new ArrayList<String>();
//ArrayList<String>playerTwo = new ArrayList<String>();
String[] playerOne = new String[10];
String[] playerTwo = new String[10];
 
[Code] .....

ignore the boolean methods I was just building the structure of the program. The print file is what is outputting this:

null
null
null
null
null
null

public class WinningHand extends PokerFile {
//ArrayList<String> p1 = new ArrayList<String>();
//ArrayList<String> p2 = new ArrayList<String>();
String[] p1 = new String[6];
String[] p2 = new String[6];
WinningHand(String[] p1,String[] p2)

[Code] ....

View Replies View Related

Sending SMS Using SMSLib Using ProxyServer

Dec 23, 2014

New to SMSLib. I checked some samples and docs but did not get any ref/poc wherein I can send SMS with following set-up.

1. I want to send SMS from PC which is connected to internet in office network, where I am using proxy settings to connect to internet.(Basically office PC used in LAN environment)

2. I am not sure how to set the Modem settings in this scenario.

3. What i want - want to test SMS functionality in office environment and would like to send SMS to android based mobile using SMSLib library.

4. I have done SMSLib set-up on my PC and have all the required jars/dlls placed at proper location. So no issues related with set-up. Set-up is on windows platform.

5. I have written sample POC by referring some blogs/SMSLib docs. But as mentioned in points 1 and 2 above, am not getting how to write the code.

View Replies View Related

Exception While Sending Email

Dec 15, 2014

I am trying send email .So I have downloaded javaEE and javamail jar files and added buildpath.And wrote this code below .But I am getting this exception.

Exception in thread "main" java.lang.RuntimeException: javax.mail.AuthenticationFailedException: 534-5.7.14 <https://accounts.google.com/ContinueSignIn?sarp=1&scc=1&plt=AKgnsbskV
534-5.7.14 ggcPi6MBZ4h8CCyCk2TG9EhiTGyE5MVBv7B3k7DsCldqjCuFvMTQG6aAbatrAWggH29muG
534-5.7.14 dzVh1kUYgMgNHAN558QRCnTjrNtUGv34Ul4pzUaansBuBfB0Kpz6_q7JTbrUuAmlZplouA
534-5.7.14 AHDXpFtuCkd-W17tHrZS5mqgVVxAcuKc-7TkhCDGShnfRBWU2R8v-gfvIQShszqsZmCl0i

[Code] .....

What am i missing here.

public static void main(String[] args) {
final String username = "mymail@gmail.com";
final String password = "mypass";
Properties props = new Properties();
props.put("mail.smtp.auth", "true");

[Code] .....

View Replies View Related

Sending A File To Web Page

Feb 20, 2014

I am new to java (been Reading for 2 days now), and have almost no knowledge on programming (I am a Mechanical Engineer).The problem I have is that I have to upload 5,000 files to a web page (each one is name B001400XXXX.pdf in consecutive order).I have managed to access the web page and select a few form elements using watij, but I am having a hard time sending my pdf file to the server. This is what I have so far:

Java Code:
import org.watij.webspec.dsl.WebSpec;
public class NewClass {
public static void main(String[] args) {

[code]....

View Replies View Related

Sending Byte Arrays Over TCP / IP?

Sep 15, 2014

I need to send a byte array across a network. I know how to do this. (server->client)

byte[] myArray = new byte[]{0,1,2,3,4,5,6,7,8,9};
DataOutputStream.write(myArray);

... and I know how to receive it.

byte[] myArray = new byte[10];
DataInputStream.read(myArray);

When I send over one of these arrays, it ends up stopping storing values in the array when only about half the array is received, even though the array is sent from the server all at once. This results in the receiver's array, in this case, being something like {1,2,3,4,0,0,0,0,0,0}.

I can easily solve this - and already have - by simply adding a loop onto it and waiting for the bytes to all be received, as the method returns the amount of bytes actually read.

byte[] myArray = new byte[10];
int bytesRead = 0;
while( bytesRead < myArray.length) {
bytesRead += DataInputStream.read( myArray, bytesRead, myArray.length - bytesRead );
}

I am simply wondering if there is a better solution to this, as the current solution isn't that elegant. Did I do something wrong to cause only a part of the array to be sent first? Would it be better to use DataInputStream.readByte() to read off the bytes one by one rather than an array at once, and then store them in an array afterward? Would this cause a performance decrease as each byte is read individually? (I'm sending an array of several million bytes)

View Replies View Related

Sending Mail From JSP File

Jan 23, 2014

I want to send email from my jsp file .. And I have a html code which contains form and inputs. How can I send the email? And I am using netbeans ..

View Replies View Related

Sending SMS Through GSM Modem Using AT Commands

Sep 3, 2014

Java code to send sms through gsm modem using AT commands..

View Replies View Related

Sending Values For GUI Fields

Jul 9, 2014

I have a simple class, called InputManager, which has methods that communicate with another class DatabaseManager which has access to Database which is actually object that contains information about actual database.

My JFrame has Navigation class (extends JPanel). There I put all needed JButtons, JLists and so on.. This class has instance of InputManager and when user interacts with GUI components inside of it, Navigation calls InputManager methods, it then analyses the call and calls needed methods on DeviceManager, which then sends queries to Database and etc.

The problem is, that at the beginning (when user runs a program), I want to get information (which is actually values for my GUI components ) from Database. It could, for example, create another DatabaseManager and connect to the Database to get information, but it is okay to have two objects?

I was also thinking about sending same DatabaseManager object through InputManager to Navigation, but it seems strange for me to have two objects, which can interact with each other in both directions(Class A has instance of Class B, and Class B has instance of Class A). Is there anything bad this can do?

Also what I noticed that it seems odd that GUI class would have to get information from database. (Logic in GUI class).

View Replies View Related

Sending XML Records To Sax Parser Using Buffer

Mar 26, 2014

i am having a below piece of code in my worker thread. In my output i am getting xml records from the database. I'm sending this output to a input stream & finally to a sax parser.My query is, before sending to the parser i need to store the input stream in buffer. The buffer should store 1000 records. For every 1000 records the parser should be called from buffer.

while (orset.next()) {
output = orset.getString("xmlrecord");
writeCount++;
InputStream in = new ByteArrayInputStream(output.getBytes("UTF-8"));
InputStream inputStream = new ByteArrayInputStream(output.getBytes("UTF-8"));
Reader reader = new InputStreamReader(inputStream,"UTF-8");

[code]....

View Replies View Related

Sending Message From One Client To Another Via Server?

Apr 2, 2014

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");

[code]....

View Replies View Related

Servlets :: Sending A Form Using JavaScript

Oct 8, 2014

I just want to to ask how can I send a form to a servlet using javascript?

Here's my form:

<form id="movieForm" class="form-signin" action="addnewmovie" method="POST"
enctype="multipart/form-data">
<h1 class="text-center movie-title">Add New Movie</h1>
<div class="row">
<div class="col-md-12">
<input id="movieId" type="text" class="input-hide form-control"
placeholder="Movie ID">

[Code] ....

This button will responsible for sending:

<button id="add-new-movie"
class="button-position btn btn-primary btn-block"
type="submit" onClick="submitForm();">Add Movie</button>

Note that I include file uploading in the form.

View Replies View Related

JSP :: Using SetAttribute For Sending Parameters To Servlet?

Apr 15, 2015

Im coding like this:

<% request.setAttribute("from", new String("test"));%>

And the I try to send the "from" value to my controller like this:

<p><a href="UserController?action=listNoDeletedFilterdUsers&from=<c:out value="${request.getAttribute('from')}"/>">
Eliminar usuarios por rango de fechas</a></p>

When I press the link and chech the HTML generated it looks like this:

<p><a href="UserController?action=listNoDeletedFilterdUsers&from=

It is not getting the value of the request which I suppose is been set at the setAttribute line of code.

View Replies View Related







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