i have build the gui but i am having problem with implementing the tcp/udp. can somebody help me.
i have server and client. the server can chat with the client. when i tried to to use the udp of tcp the gui seems hangs..
this is the code for server - package ds;
-
-
import java.awt.event.ActionEvent;
-
import java.awt.event.ActionListener;
-
import java.io.*;
-
import java.net.*;
-
import java.util.*;
-
import java.awt.*;
-
import javax.swing.*;
-
import javax.swing.border.TitledBorder;
-
-
public class Server extends JFrame implements ActionListener {
-
// Text area for displaying contents
-
private JTextField toclient = new JTextField();
-
private JTextArea display = new JTextArea();
-
private JButton send = new JButton("Send/Start Server");
-
public DatagramSocket aSocket;
-
public DatagramPacket request;
-
public DatagramPacket reply;
-
-
public static void main(String[] args) {
-
-
new Server();
-
}
-
-
public void actionPerformed(ActionEvent e) {
-
if (e.getSource() == send){
-
try {
-
-
String msg = toclient.getText();
-
byte [] xy = msg.getBytes();
-
reply = new DatagramPacket(xy,xy.length,
-
request.getAddress(), request.getPort());
-
-
//sending a reply message to client
-
aSocket.send(reply);
-
} catch (IOException ex) {
-
ex.printStackTrace();
-
}
-
}
-
}
-
-
public Server() {
-
-
JPanel input = new JPanel();
-
input.setLayout(new BorderLayout());
-
input.setBorder(new TitledBorder("Enter Message"));
-
input.add(toclient, BorderLayout.CENTER);
-
input.add(send, BorderLayout.EAST);
-
-
JPanel output = new JPanel();
-
output.setLayout(new BorderLayout());
-
output.setBorder(new TitledBorder("Conversation"));
-
output.add(display, BorderLayout.CENTER);
-
-
JPanel gabung = new JPanel();
-
gabung.setLayout(new GridLayout(2, 1));
-
gabung.add(input);
-
gabung.add(output);
-
-
this.getContentPane().add(gabung, BorderLayout.NORTH);
-
send.addActionListener(this);
-
-
setTitle("Chat Server");
-
setSize(500, 300);
-
setVisible(true);
-
-
-
-
}
-
-
-
}
this is client - package ds;
-
-
import java.awt.event.ActionEvent;
-
import java.awt.event.ActionListener;
-
import java.io.*;
-
import java.net.*;
-
import java.util.*;
-
import java.awt.*;
-
import javax.swing.*;
-
import javax.swing.border.TitledBorder;
-
-
public class Client extends JFrame implements ActionListener {
-
// Text area for displaying contents
-
private JTextField toclient = new JTextField();
-
private JTextArea display = new JTextArea();
-
private JButton send = new JButton("Send");
-
-
public static void main(String[] args) {
-
new Client();
-
}
-
-
public void actionPerformed(ActionEvent e) {
-
}
-
-
public Client() {
-
-
JPanel input = new JPanel();
-
input.setLayout(new BorderLayout());
-
input.setBorder(new TitledBorder("Enter Message"));
-
input.add(toclient, BorderLayout.CENTER);
-
input.add(send, BorderLayout.EAST);
-
-
JPanel output = new JPanel();
-
output.setLayout(new BorderLayout());
-
output.setBorder(new TitledBorder("Conversation"));
-
output.add(display, BorderLayout.CENTER);
-
-
JPanel gabung = new JPanel();
-
gabung.setLayout(new GridLayout(2, 1));
-
gabung.add(input);
-
gabung.add(output);
-
-
this.getContentPane().add(gabung, BorderLayout.NORTH);
-
-
setTitle("Chat Client");
-
setSize(500, 300);
-
setVisible(true);
-
-
-
-
}
-
-
-
-
}
where do i need to implement the udp or tcp?
1 24522
You can do it simply using tcp. Use "ServerSock et" on server side to accept the connection from client. Using "Socket" class on client side connect to the server. Then u can communicate by creating the input and output streams for the socket.
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: RobertMaas |
last post by:
After many years of using LISP, I'm taking a class in Java and finding
the two roughly comparable in some ways and very different in other
ways. Each has a decent size library of useful utilities as a standard
portable part of the core language, the LISP package, and the java.lang
package, respectively. Both have big integers, although only LISP has
rationals as far as I can tell. Because CL supports keyword arguments,
it has a wider range...
|
by: A |
last post by:
Hi all!
I am currently working on a project where I need to create a web-based chat
application that will be used for auctions.
If possible, could I get some advice on how to create chat applications and
which part of the .NET framework should I delve into? I would really
appreciate the help!
Cheers,
|
by: patrick_woflian |
last post by:
hey guys, im just writing a basic calculation at the moment, before
building on it for an A-Level piece of work. i can add/divide etc...
two numbers together yet i am having a major problem with the following
calculation:
z = x! / (x- y)!
The following code is my attempt and i was hoping for a point in the
right direction as too where i am going wrong.. cheers
|
by: raski |
last post by:
hello all!
how is it possible to backdoor a java based chat room?
www.iskon.hr/chat/chat.jsp
|
by: raski |
last post by:
i was wondering if any of you guys would know any trick i could
pull on some of my friends on a java based chat room. nothing harmful, only
for playing around...
www.iskon.hr/chat/chat.jsp
that's the link. i would be thankful if you could mail me some...
Thanx in advance
| |
by: jason.m.ho |
last post by:
>From the common user perspective (like my grandma), why would they care
if its a java applet or an ajax application? Say I want to make a chat
system on my website...If i'm doing really involved Comet push-style
data communication, and rendering everything using DHTML, why would
users prefer that over a java applet?
Moreover, say I use a java applet to transfer data through a socket
connection, then use DHTML to display the data, so...
|
by: watusiboy |
last post by:
i have created a chat application in java. the server listens to clients, receive messages from them, and send these message to other clients. i intend to embed the client program as an applet in a website that i'm developing. i am building this website using apache-php-mysql
is there a way to trigger the server program (which is a java class) through php. what i want is that as apache starts, the server program is also executed. is this...
|
by: linksterman |
last post by:
I am making this pretty basic chat project, and I found this echo server on the internet and decided to modify it my needs (much of the methods and fields are the same).
Basically what my program does is acts like a chat room. One computer runs the server which other java programs connect to and can communicate with one another. The problem is that this server I run is horribly inefficient.
I had to use 2 threads for each connection...
|
by: sreekandank |
last post by:
Hi.....
I have done the program for simple chat application in java....as given below....
server.java
import java.net.*;
import java.io.*;
public class server
{
public static void main(String args)throws Exception
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |