Client-Server Mini Program Is Not Communicating Right - Blocking Read Line Does Not Block?

Feb 3, 2014

Me and my brother decided to make a relatively simple client/server program where clients get into a simple chat lobby and can invite others to play small games(like pong). The basic server code has been written, and we have made a special client that is used for debugging.

We use a self-defined protocol of Strings where a message looks like "4-|user,pass". The number before the delimiter "-|" is the operation code, that tells the server what kind of message this client sends. Based on that number, the server dispatches the message to the appropriate handler method. 4 is authentication for example, and the handler looks the user and pass up in a file and if found, returns true, otherwise, false. Then the server responds to the clinet with 2-|"any message" where the client will recognize opcode 2 as a "authentication accepted" and proceed with the next part of client code. In a similar way, we plan to write all message types(both in the game, in the lobby and in a game setup room).

While testing we ran into a problem where the BufferedReader .readLine() does not seem to be a blocking call like it should be, so the client keeps spamming 'null' in the output field that we made to see the server response to the message we send. When we try to debug the server code and set breakpoints at the suspicious locations, it strangely skips both while(true) loops without activating either breakpoint and executes the finally{} code, even though the client did not close the connection and the second while loop was never entered. The first while loop IS entered though, because the test client gets a "0" on its output, which is the server message indicating "please authenticate yourself".

We decided to use messages in a string format and decode it at both sides as it seemed easier than transmitting java objects and making sure they are of the same type, also for reducing overhead as much of possible.URL....

package Chatroom;
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.HashSet;

[code]....

View Replies


ADVERTISEMENT

Communicating Between Client And Server Sockets In Java

Apr 3, 2014

I'm working on an assignment right now which involves passing a variable series of numbers to the Server to be sorted into the correct order and returned to the client.

So far I have it connecting to the server and asking for my numbers, and I am entering each number and pressing return, and it is accepting each number individually.

One (smaller I think) problem i'm having is with the client code, specifically the while loop.. I've tried to code it so that when I enter a full stop ('.') the program will stop asking me for more numbers and move on to sending them to the server.. but instead it just crashes giving an error.. heres an example

"Enter a number: 1
Enter a number: 3
Enter a number: 2
Enter a number: 1.
java.lang.NumberFormatException: For input string: "1."
at java.lang.NumberFormatException.forInputString(Num berFormatException.java:65)

[Code] ....

Here's the client code in full

package numberSortprogram;
import java.io.*;
import java.net.ServerSocket;
public class NumSortClient {
public static void main(String[] args) {
InputStreamReader is = new InputStreamReader(System.in);
[Code] ....

The big problem that I have is figuring out how to send the sorted array back to the client..

So, what im trying to get to happen is-

-Client is asked to enter numbers
-Client enters series of numbers into an array
-Array is converted to a string and sent to the server
-String is then split into an array of strings and sorted using compareTo (don't know if this is the best way?)
-Sorted array is sent back to client and displayed.

fyi this is making use of streamsockets..

All of the rest of my code is below:

package numberSortprogram;
import java.io.IOException;
import java.net.*;
import java.util.regex.PatternSyntaxException;
public class NumSortServer {
public static void main(String[] args) {
int serverPort = 4444; // default port
if (args.length == 1 )

[Code] .....

View Replies View Related

Client / Server Using PIPE Line?

Apr 20, 2015

I have a program using Pipe line to exchange the infomation in the Client-Server model. Can I separate out main function and then put into Server main and Client main?

//PipeEchoServer
public class PipedEchoServer extends Thread {
PipedInputStream readPipe;
PipedOutputStream writePipe;
PipedEchoServer(PipedInputStream readPipe, PipedOutputStream writePipe){
this.readPipe = readPipe;

[code]....

View Replies View Related

Modify Or Read Http Message Before Sending To Server Within Client

Feb 25, 2014

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.

View Replies View Related

How To Add Server Client Relation In Program

Feb 17, 2014

I have to develop a code in parallel which is implemented in sequential yet. How to add the server client relation in the program so that work can be divided into multiple clients.

View Replies View Related

Client / Server Chat Program

Dec 6, 2014

So i wrote this text to try and create a simple chat program that does the following: Prepend names to messages, announce entrance and exit of chat, display user list, and share a whiteboard.So far the Server seems to be working but the Chat Client is throwing errors at me left and right..

CURRENT ERROR:
Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation. All rights reserved.

C:Windowssystem32>cd..
C:Windows>cd..
C:>Usersjaydesktopchat
'Usersjaydesktopchat' is not recognized as an internal or external command,
operable program or batch file.

[code]....

View Replies View Related

Debugging Client-server Program In Eclipse

Sep 27, 2014

I've been provided a code skeleton for what must be done, but despite my best efforts to make things work, I'm coming up dry (obviously, due to a lack of knowledge.) One thing that might work is if I knew how to debug this type of application, line-by-line, to see exactly what is going on. Obviously, it's easy enough to debug the client part, but moving over to the server part, I haven't been able to figure that out (I'm using Eclipse.)

Anyways, here's the code I've got so far:

Client.java:
import java.io.*;
import java.net.*;

[code]....

View Replies View Related

Java UDP Client Server Program Not Working

Apr 18, 2014

I am currently writing two java classes (client and server). The client takes an input number form keyboard and sends it to the server. The server then multiplies this number by two and sends it back to the client. The numbers should also be printed to screen along the way, for example if I input the number 3 I should get

"From Client: 3" "From Server: 6"

They should continuously do this unless a negative number is received by the client, say for example the number -3 is sent to the server and it returns -6.

The code I have for the two classes so far is:

import java.io.*;
import java.net.*;
import java.nio.ByteBuffer;
import java.util.Scanner;
class Client {
public static void main(String args[]) throws Exception {
DatagramSocket clientSocket = new DatagramSocket();

[Code] .....

Currently, when I run the program all I get is an output of the number first entered. I am aware it requires a loop but I don't know where and what the condition should be.

Also if I wanted to adapt this so that it would take the integer from client and subtract two at the server and return to client who sends back to server to keep subtracting two unless it reaches a negative number at which point the client will terminate the program - how might I do this.

I do realise there needs to be a while loop in the above code, but I wanted to test it sent the number from client to server and its not doing it. All I get is a print screen of 'enter number' and then the number I enter.

View Replies View Related

Running Program From Server On Client Machine

Aug 9, 2014

I had some questions about a theoretical java program. Say you had a java program on a linux server/pc that referenced a folder on that server. And say you had a Client PC (Windows) that had a share folder to that java program.

If that windows client PC tried to run the program would it run (with a GUI if it had one) and would the main directory of the java program still be on the linux server or would it be on the windows computer since that is the computer that is running the program?

Basically I have a program I am trying to find the best way to run it remotely on a windows computer but it references files on the linux server it is located at and needs to put files it creates there as well. I am just trying to make sure I understand my theory here on how the program will run if it IS run remotely.

View Replies View Related

Instant Messaging Program Between Server And Client

Mar 9, 2015

My overall goal is to create a server that can receive a message from a client and send an automatic reply in captial letters..As well as having the incoming messages decoded to display the header information..The server also needs to save a log of incoming and outgoing commutations..The client needs to be able to attacha text or JPG file and be able to coummucnate with the client.Okay this is what i have so far

client = [URL] .... Cear1v3g
server= [URL] .... hh3uCBqw

I really need them to be able to communicate with each other with messages i am struggling making that work as so far they can talk only to themselves the message aren't getting sent between them, let alone adding the other feutures.

View Replies View Related

Simple Chat Program With Client / Server EOFException

Feb 13, 2015

When I Start Server and login from client everything goes fine but as soon as I want to send amessage or use showIn or even logOut .

Get below error

Exception creating new Input/output Streams: java.io.EOFException

View Replies View Related

FTP Program With Server Is Not Sending Existing Files On Client

Feb 8, 2014

I'm creating ftp program which server will send not existing files on client to him.

There is method responsible for creating connection and sending list of files on client written by me.

Java Code:

[JAVA]//client method
public void enableClient() throws IOException, ClassNotFoundException {
System.out.print("Rozpoczęto działanie klienta");
strIP = jtfIP.getText();
intPort = Integer.parseInt(jtfNrPortu.getText());
clientPath= "C:/serweris/";
sck = new Socket(strIP, intPort);

[Code]....

View Replies View Related

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

Swing/AWT/SWT :: Mini Paint Program - Changing Size Of Shapes

Jun 4, 2014

I am currently writing a small drawing program and I am having trouble with changing the size of the shapes. To do this, I have to access the arraylist shapes, check whether pressedX/pressedY is on any of the shapes in the arraylist using the findShape() method and then when released, uses moveBy() in the Rectangle/Oval/Line class and moveShape() in the miniDraw class to move the shape and draw it in the newreleasedX/releasedY position.

So far I think I have pin pointed the problem to being the method in all the shapes classes, that checks whether the pressedX/pressedY which is the on() method, and the findShape() method in the miniDraw class.

This is the minidraw class

import ecs100.*;
import java.awt.Color;
import java.io.*;
import java.util.*;
import javax.swing.JColorChooser;

[Code] .....

View Replies View Related

JUnit Test - Read From Text Line By Line And Save Words In FileOnTable

Nov 21, 2014

I have wrote this class who read from text line by line and save the words in fileOnTable.. Now i don't know what to read in ReadOffer to save the words in object offers and return this.. One more question.. What JUnit test can write for this code..?

package com.example.crazysellout.UserSide;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

[Code] ....

View Replies View Related

Read File Line By Line

Dec 8, 2014

how to read file line by line ? Namely my input file I want to read look as follow:

AAA 1, 1
12 222 12
AAA 2, 2
11 122 11
 
My output file should look as follow:

1, 1, 12
1, 1 222
1, 1, 12
2, 2, 11
2, 2, 122
2, 2, 11
 
I think the lines need to be stored in ArrayList, then I would like those lines to write to csv file, but how on read I can construct such output file? This is my code for reading file
  
public ArrayList readFile(String filename)
{
try
{

[Code]....

View Replies View Related

Testing TCP Client And Server

Oct 22, 2014

I am attempting to test a TCP Client and Server for an assignment I am doing in class. The goal here is to "test your client and Server applications by transferring (i) a file having 10,000+ lines (see supplied big-file1.txt having 12000+ lines), (ii) a file having 20,000+ lines (you may create one of your own from big-file1.txt, or obtain a large size file from the Google website at [URL] ...). Then, compute and display the total transfer time of the files at both of the sides separately (your choice in millisecond/second)."

I have created the TCPClient and TCPServer java classes, ran the server first and then the client, and using mathematical formulas to calculate the transfer time. Trouble is, I'm having trouble testing the client and server in the file area and not the area where I had to input a line, let the server print it, and then have the client eliminate the articles from the line. I need testing the file. Here is my code so far:

TCPClient:

package tcpclient;
import java.io.*;
import java.net.*;
public class TCPClient {
public static void main(String[] args) throws IOException{
// TODO Auto-generated method stub
String sentence;

[code] ....

How to fix the code so that the time in seconds does not output as 60 for both files and that the files go through the exchange?

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

RMI / How Can Client Send A Message To Server

Sep 3, 2014

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.

View Replies View Related

Client Info On Server Side

Apr 6, 2014

I want to ask that, when a server listen to A port and it accepts a request from a client then the server accepts the request using accept method,but how does the server get the info about the client like wat is the port no and ip address of the client,I read a answer regarding this that Server never gets the port no of client only the ip address and it connects to client using a connection stream but as far I know from networking, a device must have the ip address and port no of the device it wants to connect to.

View Replies View Related

Client And Server - Reading From Socket

Jul 22, 2014

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?

View Replies View Related

EJB / EE :: SSL Works Only If Client And Server Are At Same Host

Jun 9, 2014

I have gf 4.0.1 and swing client. I want to get EJB over SSL. I've set all certificates. However, I can get it work only when client and server are at the same host. What I see in tcpdump when they are at the same host:

10.0.17.2.48524 > 10.0.17.2.3820: Flags [P.], cksum 0x378f (incorrect -> 0xf2b6), seq 399:756, ack 1085, win 273, options [nop,nop,TS val 347297976 ecr 347297966], length 357
13:01:26.334898 IP (tos 0x0, ttl 64, id 51559, offset 0, flags [DF], proto TCP (6), length 665)
10.0.17.2.3820 > 10.0.17.2.48524: Flags [P.], cksum 0x388f (incorrect -> 0x626d), seq 1085:1698, ack 756, win 273, options [nop,nop,TS val 347297977 ecr 347297976], length 613

[code]...

View Replies View Related

Running Server And Client From Two Different JButton

Mar 10, 2014

I am looking to run Server and Client from two different JButton.

When I click on start Server button, the server starts to run but I cannot click on start Client button to start the client. Here the code for server:

Java Code:

public void actionPerformed(ActionEvent e) {
Client c = new Client();
c.run();
} mh_sh_highlight_all('java');

View Replies View Related

Simple Server / Client Chat

Dec 28, 2014

I've been trying to create a server/client chat program, but I keep running into areas where I'm not really sure how to work it. I've run into a wall where my client just sits and spins instead of working. URL.... I can work out the dynamic parts later, I just want to understand the meat and potatoes of reading from sockets and writing to sockets (and how to do both at the same time).

View Replies View Related

SSL Client / Server Mutual Authentication

May 2, 2015

I'm trying to build a SSL mutual authenticating private server. I'm not sure what keystores, truststores, or certificates I need to accomplish this. I made keystores for both programs using:

keytool -genkey -keyalg RSA -alias selfsigned -keystore keystore.jks -storepass password -validity 360 -keysize 2048

The server starts up fine, but when I run the client they both give errors.

Server code:

System.setProperty("javax.net.ssl.keyStore", "CLA.jks");
System.setProperty("javax.net.ssl.keyStorePassword", "password");
SSLServerSocketFactory sslServerSocketfactory = (SSLServerSocketFactory)SSLServerSocketFactory.getDefault();
SSLServerSocket sslServerSocket = (SSLServerSocket)sslServerSocketfactory.createServerSocket(9090);
SSLSocket s = (SSLSocket)sslServerSocket.accept();
BufferedReader in =
new BufferedReader(new InputStreamReader(s.getInputStream()));

[code]...

View Replies View Related

RMI With Doing Calculations Across A Server / Client Platform

Apr 6, 2014

It's an RMI program that has to be able to return the mean, mode and median of a set of numbers.It's composed of 4 classes; a client, an implementation class (with the math), an Interface, and a server class.

import java.rmi.NotBoundException;
import java.rmi.RMISecurityManager;
import java.rmi.RemoteException;
import java.rmi.registry.LocateRegistry;
import java.rmi.registry.Registry;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;
import java.io.*;
 
[code]....

View Replies View Related







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