473,883 Members | 1,743 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Java server output problem.

TheMan1
19 New Member
Hi, I'm trying to read output from a server. In the client I have done:
Expand|Select|Wrap|Line Numbers
  1. Socket clientSocket = new Socket("127.0.0.1", 7777); 
  2. DataOutputStream toServer = new DataOutputStream(clientSocket.getOutputStream());        
  3.         toServer.writeBytes("Hello" + '\n');
  4. BufferedReader fromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
  5. String serverMessage = fromServer.readLine();
  6. clientSocket.close();
When I click a button on my main java frame (I'm using one as a simple GUI), it will somehow get serverMessage, and display it in a text field. The problem is it doesn't seem to be executing that second last line there, because it's not a console application (as stated, uses a java frame as a GUI). At least I think that's the problem... since serverMessage doesn't seem to get a String value from the readLine().
Or is it possible my sockets aren't connecting? It works when I implement both client and server (without GUI) as console apps...
Help? Thanks.

PS: here's the server code:
Expand|Select|Wrap|Line Numbers
  1. String clientMessage;
  2. String capitalizedMessage;
  3. ServerSocket welcomeSocket = new ServerSocket(7777);
  4. while(true)
  5. {
  6.             Socket connectionSocket = welcomeSocket.accept();
  7.             System.out.println("Connection established.");
  8.             BufferedReader fromClient = new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
  9.             DataOutputStream toClient = new DataOutputStream(connectionSocket.getOutputStream());
  10.             clientMessage = fromClient.readLine();
  11.             capitalizedMessage = clientMessage.toUpperCase() + '\n';
  12.             toClient.writeBytes(capitalizedMessage);
  13. }
Apr 3 '08 #1
1 1768
JosAH
11,448 Recognized Expert MVP
It seems you're dealing with the same problem as in this thread.

kind regards,

Jos
Apr 3 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
4499
by: JShurmatz | last post by:
If anyone can shed some light on this problem I would greatly appreciate it. I am unsuccessfully trying to use a database connnection retrieved from a pool configured using Java System Web Server 6.1 with the SQL Server 2000 JDBC Driver. The background: 1. I have downloaded the SQL Server 2000 JDBC Driver and installed it on the web server.
1
5440
by: Krzysztof Pa¼ | last post by:
Hi, I want to make simple client in phyton, which would be able to communicate with Java server using SSL sockets. There is the Java clients, which is doing this - so I'm pretty sure, that Java server works OK. I've heard, that P2.3 has SSL support included in himself and also, I was trying P2.2 with pyOpenSSL wrappers and extensions, but unsuccesfuly... So, could you give me a few lines of python code which makes such things:
133
8631
by: Gaurav | last post by:
http://www.sys-con.com/story/print.cfm?storyid=45250 Any comments? Thanks Gaurav
0
2785
by: netgeni59 | last post by:
Hello fellow C# friends, I am trying to write a C# TCP client that was formerly written in Java. The server must still remain in Java. I cannot get text data from the C# client to be received by the Java TCP server. No matter how I try to send data from the client to the server, the Java server DataInputStream readUTF() method never returns with any data. Can someone please shed some light on this problem? Thanks.
7
3100
by: Jorgen Haukland, Norway | last post by:
Hi, I have created a Java webservice which runs in IBM WebSphere appserver. I take the WSDL-file and create a VS.NET WinForm application and calls the service running on my PC and everything works fine. So I deploy the webservice on a remote machine (Linux box) and I get an error when calling the service. BUT: I can retrieve the WSDL and make a webreference in my VS.NET project, so obviously I (or more correct: My VS.NET project) am...
6
2444
by: Rhino | last post by:
I'm trying to debug a simple Java UDF written in the DB2General style within Eclipse. I'm getting a java.lang.UnsatisfiedLinkError when I execute the set() method in the UDF. I know that the UnsatisfiedLinkError has something to do with a DLL that is not visible but I'm not sure why I'm having the problem given that both db2java.zip and db2jcc.jar are visible on my classpath and each of them contain the COM.ibm.db2.app.UDF class with a...
2
6985
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
1
24536
eyeofsoul
by: eyeofsoul | last post by:
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.*;
10
4272
by: Elaine121 | last post by:
Hi i've been batteling for hours and can't seem to find the problem. When my server runs and I press the connect button the gui freezes until the client gui is terminated.. only then the gui becomes active again and displays the messages. Here is my server code: import java.io.*; import java.net.*; public class serverForm extends javax.swing.JFrame { private PrintWriter output = null;
0
9942
marktang
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...
0
9792
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11144
Oralloy
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...
0
10747
jinu1996
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...
0
9577
agi2029
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...
0
7133
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();...
0
5994
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4616
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4223
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.