Small Chat Lobby

Feb 4, 2014

Me and my brother are working on a small java project to learn network programming and get some experience working with networking code. We 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".

Also, if we approach things in a dumb way that can be done way more efficiently or easier to read/manage, please do tell. Keep in mind we are beginners though! 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....

The server code:

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;

/**
* This is the main server class. It is the core of the server functionality, and the listener for incoming clients that will spawn threads to deal with clients, track their information, change their states and ultimately, clean up after all clients by keeping the data structures up to date.

[code]...

View Replies


ADVERTISEMENT

Java Chat Using MySQL / How To Keep Updating Chat

Nov 12, 2014

Using MySQL to store the chat data/users and then recieve the chat data every time the chat table updates because someone entered a new message. I am woundering if this is the right way to do it or should try something else?

What I am looking for is someway to run a query each time the database has been updated or receive data from the database each 10 sec, is it even posible, if yes then how? Been trying to look into threading, but do not seem solve this problem and cant find any information about it.

View Replies View Related

Small Text Editor

Jun 23, 2014

I'm having a problem with a small text editor I'm trying to create. I have implemented a panel of labels, containing line numbers, on the left of a scrollable text area. The panel is designed to size such that it fits the larger numbers whenever they appear. It does that very well, actually, until either one of the scrollbars appear. As soon as one does appear, it immediately shrinks in width. The horizontal scrollbar even blocks the view a little, making it impossible to see what you are writing on the very last line.

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Main implements KeyListener {
public static JPanel tab = new JPanel(false);
public static JTextArea text = new JTextArea();
public static JScrollPane scroll, reflex;
public static JPanel lines;

[code]...

Explanation of the code: There is a main panel which embodies a text area and another container filled with labels of line numbers.Both the text area and line number panel have scroll panels attached. They are synchronized, in order to scroll at the same time.

The main class contains a static function "position" which generates a GridBagConstraints, created for the convenience of single-line creation of constraints.It also implements the KeyListener interface, and waits for change in the amount of lines inside the text area. Afterwards, it changes the panel of labels accordingly.

View Replies View Related

Building A Small Text Based RPG

Dec 18, 2014

i'm totally new to Java.I'm making a small text based RPG and this is what i've come up for now.

Java Code:

import java.util.Scanner;
class Main {
public static void main(String args[]){
Scanner input = new Scanner(System.in);
Player playerObject = new Player();

[code]....

My thing is that i want the user to enter 'Caucasian' or another race in the console below and i want it to be saved in a variable or something else in the Player Class that i can later use it in texts or something else. My question is how can i do it?

I tried like 'int Mongoloid = 1; int Caucasian = 2;'

And the same with the others, and after that i tried to use them with the Switch Statement but it did not work.

View Replies View Related

Stuck On Porting Small Segment Of JavaScript To Java

Mar 3, 2014

I'm fairly good at Java, but somewhat at a loss when the some of the JavaScript below is mentioned. I've attempted to port the below code, but I'm finding it somewhat difficult.

Parts of JavaScript I'm stuck at porting:

1. I'm stuck on the return statement on the 3rd line.

2. Similarly the lines utilizing "charCodeAt", as I keep getting error "Cannot invoke charCodeAt(int) on the primitive type char"

3. Also on the second to last line, I keep getting the error "Cannot invoke padLZ(int) on the primitive type int".

Link to original javascript

Convert between Latitude/Longitude & OS National Grid Reference points

Original JavaScript

Java Code:

OsGridRef.prototype.toString = function(digits) {
digits = (typeof digits == 'undefined') ? 10 : digits;
e = this.easting, n = this.northing;
if (e==NaN || n==NaN) return '??';
// get the 100km-grid indices
var e100k = Math.floor(e/100000), n100k = Math.floor(n/100000);

[Code] ....

View Replies View Related

Accurately Converting Units Involving Extremely Small Numbers?

Jun 16, 2014

I need to convert units accurately. Some of these units include angstroms (0.1nm) and astronomical units or light years. I can't seem to accurately perform these equations (probably mostly because of lack of a proper conversion formula). For example:

1 angstrom = 1.79985601 × 10^-14 leagues (or, 0.00000000000001799856 leagues).

To perform the conversion right now, I'm simply multiplying the angstroms by 0.00000000000001799856. However, inputting 55560000000000 (angstroms in one league) results in 0.9999999936. Why is this? Is it possible to work around it? I believe there's a term for the inability for a computer to process 1/3rd properly, but I can't remember what it's called - is that the problem?

I am using BigDecimals for all equations.

Edit: a mod can change the title if they think another is more fitting.

View Replies View Related

Write A Small Program That Will Calculate Gain / Loss Of Sale Of Stock

Jan 24, 2014

I am trying to write a small program that will calculate the gain and/or loss of the sale of stock. The program will ask the user for the number of shares, the purchase price and the selling price. I am pretty sure that the errors is coming from my calculations in the program.

import java.util.Scanner;
public class investmentCalculator {
public static void main (String[] args) {
Scanner input = new Scanner(System.in);
//User input for number of shares
System.out.print("Enter the number of shares: ");
double shares = input.nextDouble();
 
[code]....

View Replies View Related

Strings - Change Every Capital Letter Into Small Letter And Vise Versa

Oct 22, 2014

I have a problem with functions connected to strings.

I have a random String, e.g. "Hello World!" and I have to change every capital Letter into a small letter and vise versa. This alone would be fairly simple, but I have to do it with two other strings.

lowercase= "abcde...z" and

uppercase="ABCDE...Z". Every small letter stands at the very same position as the capital letter, but in the other string.

There should be a letter for letter search in lowercase and uppercase for the letters of "Hello World".

How I could solve the task, however I need a way to search the first string, here "Hello World", according to position. A statement which does: "Give me the letter of position x". This found letter should be able to be stored in a variable or else be able to be used by another statement. And it should be compatible with a for lope.

View Replies View Related

How To Create Chat Project

Jul 8, 2014

i don't know how create that project ,

View Replies View Related

Code For Multiuser Chat With GUI

Jun 19, 2014

i am writing the code for multiuser chat with GUI and i wanna create a quiz game where the all the users i.e the clients can aniticipate in the game. is there a way where we can combine the game and the users together in a single gui screen. the game is on the left box of the gui and chat space on the right.

View Replies View Related

Voice Chat Using Java MulticastSocket

Apr 13, 2014

I am trying to implement the voice chat using java multiCastSocket programming. Taking the input from the microphone and trying to listen it on the speaker. Problem is am not hear any voice back. I debugged through it wireshark and i am receiving the packets from the multicast group address. Looks like there is some problem while i am trying to get the sound out of speaker.

/*Sender Code*/
public class MulticastAudioSender {
/** Port to use for IP Multicast sending. */
public static final int IPM_PORT = 7778;
/** Address to use for IP Multicast sending. */
public static final String IPM_ADDRESS = "235.1.1.1";
 
[Code] ....

View Replies View Related

Encrypted Video Chat Program Using JMF

Oct 23, 2014

I am trying to make an encrypted video chat program using JMF. I have successfully written the "video chat" part - which includes getting data from webcam and transmitting it using RTP, but how to get raw data video to encrypt it before it stream between the webcam and the network.

For RTP I am using RTPManager, and for reading from the webcam I am using this code:

DataSource ds;
CaptureDeviceInfo di = null;
StateHelper sh = null;System.out.println("Started Video");
String str1 = "vfw:Logitech USB Video Camera:0";
String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
String str3 = "vfw:Microsoft WDM Image Capture (Win32):0 : vfw://0";

[Code] .....

I plan on using a stream cipher for encryption, maybe RC4.

View Replies View Related

Using Socket And JSP For Web-based Chat Application

Feb 13, 2014

I am new to JSP !! and 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.

View Replies View Related

Video Chat Tool Using Java RMI

Jul 3, 2014

I am stuck in making a C/S video chat program using JAVA RMI technology. I am more familiar with Java RMI.

View Replies View Related

Java Chat Application With Springs

Nov 28, 2014

how to develop a CHAT APPLICATION using Java springs .this should be very simple client server project with rich front end IT contains login page and a chat page.

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

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

System For Emulating Conversation In Chat Rooms?

Oct 11, 2014

So for my current work I do a lot of chatting to customers, but I spent 80% of my time answering things that could be automated, I'd like to know where the best place to start would be for the following.

Being able to compile data on certain conversation parts,

for instance "How many employees do you have?/How many people work there?/how many people do you employ" would be a bunch of different ways of saying the same thing, so i could have a stock answer to that: "x employees work at Acme"

So what language and/or framework would be best for having a program like that running, and giving me an alert when it encounters a conversation direction it's not used to, so i can add in an option, so its sort of like I'm teaching at as we go, but I think it's a lot simpler than most AI haha.

Also a way of selecting and reading chat windows, like how old runescape bots used colours.

I'd like do all the data input myself, and I'd like to write or design the framework if possible, but I don't even know what keywords to use find out where I should start.

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

How To Make Video Chat Possible In Java Web Application

Mar 15, 2014

How to make video chat possible in java web application??

View Replies View Related

JSP :: How To Make Interactive Chat Like Gmail / Facebook

Feb 24, 2014

How can i make interactive chat like GMAIL, FACEBOOK.

Can it possible .. using ajax that frequently updating a portion/part/ chat box.

If we do in this way, I am sure our server will be overloaded.

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

Chat Application Working On Dynamic IP But Not On Static (server) IP

Apr 25, 2014

I have developed a window based chat application for chatting, screen sharing, file sharing, video playing.

All are working well on my local network systems (eg. dynamic server ip is 192.168.1.122). But if i try to run on my server (e.g. static server ip 50.62.8.22) it is not get connected..,

View Replies View Related

Send Emotions In Chat Application Built In Java Using Netbeans

Jan 26, 2014

how to send emotions in a chat application built in java using netbeans ?

View Replies View Related

UDP Voice Chat - Play With The Index Of Mixer Info Array

Jan 18, 2012

I was trying to make a UDP voice chat but i couldn't make the receive method work! so i just move on to work with TCP. I found a simple code that i found it pretty easy to understand,but i couldn't make it work, always stuck within exception.

Here is the output I got:

Available mixers:

Java Sound Audio Engine

Microsoft Sound Mapper

WinOS,waveOut,multi threaded

java.lang.IllegalArgumentException: Line unsupported: interface TargetDataLine supporting format PCM_SIGNED, 8000.0 Hz, 16 bit, mono, little-endian, audio data

And here is the code

sender:

Java Code:

package sender;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import javax.sound.sampled.AudioFormat;

[Code] ....

I tried to play with the index of mixerInfo array in the line

Java Code:

Mixer mixer = AudioSystem.getMixer(mixerInfo[1]); mh_sh_highlight_all('java');

But nothing happened. How I can fix that?

View Replies View Related







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