Home > Default > Simple TCP Client Program Problems

Simple TCP Client Program Problems

October 11Hits:0
Advertisement
The Code:
import java.io.*;
import java.net.*;
class TCPClient {
     public static void main(String argv[]) throws Exception
          String sentence;
          String modifiedSentence;
          BufferedReader inFromUser = new BufferedReader(
               new InputStreamReader(System.in));
          Socket clientSocket = new Socket("www.utm.edu", 80);
          DataOutputStream outToServer = new DataOutputStream(
               clientSocket.getOutputStream());
          BufferedReader inFromServer =
               new BufferedReader(new InputStreamReader(
                    clientSocket.getInputStream()));
          sentence = inFromUser.readLine();
          outToServer.writeBytes(sentence + "\r\n");
          modifiedSentence = inFromServer.readLine();
          System.out.println("FROM SERVER: " +
                                   modifiedSentence);
          clientSocket.close();
So...when the program loads the console...I type
GET /staff/bbradley/200640/cs360/test1.txt
And I'm supposed to get what's at the URL:
http://www.utm.edu/staff/bbradley/200640/cs360/test1.txt
But Instead I just get the first line of the text...any ideas?

Answers

Change the code to
import java.io.*;
import java.net.*;
class TCPClient {
public static void main(String argv[]) throws Exception
String sentence;
String modifiedSentence;
BufferedReader inFromUser = new BufferedReader(
new InputStreamReader(System.in));
Socket clientSocket = new Socket("www.utm.edu", 80);
DataOutputStream outToServer = new DataOutputStream(
clientSocket.getOutputStream());
BufferedReader inFromServer =
new BufferedReader(new InputStreamReader(
clientSocket.getInputStream()));
sentence = inFromUser.readLine();
outToServer.writeBytes(sentence + "\r\n");
modifiedSentence = inFromServer.readLine();
while(modifiedSentence!=null)
System.out.println("FROM SERVER: " +
modifiedSentence);
modifiedSentence = inFromServer.readLine();
clientSocket.close();
}

Read other 2 answers

Tags:

Related Articles

  • Simple TCP Client Program ProblemsOctober 11

    The Code: import java.io.*; import java.net.*; class TCPClient {      public static void main(String argv[]) throws Exception           String sentence;           String modifiedSentence;           BufferedReader inFromUser = new BufferedReader(     

  • Ftp Client program problem ...November 30

    Hi all . I m trying to develope a simple FTP client program which will connect to the FTP server for download a file .. Now in the start i m just trying to get the current directory of the server using -- pwd -- command . My programs executes correct

  • Simple TCP Chat program behid routerNovember 30

    Hello, I've been reading some of the examples from http://pirate.shu.edu/~wachsmut/Teaching/CSAS2214/Virtual/Lectures/chat-client-server.html, and understand how these examples work well enough to fool around with it... I have it working inside my lo

  • TCP Client Program hangs up! Please helpNovember 30

    Hi, I'm trying to send a sudio file from server to client. Before starting to send the file I take the system time at the server and send it to client. For this I use the following code. At Client: DataInputStream inFromServer2 = new DataInputStream(

  • Help with MIDlets - TCP client server programNovember 30

    Hi I am new to using MIDlets, and I wanted to create a simple TCP client server program.. I found a tutorial in J2me forums and I am able to send a single message from server(PC) to client(Phonemulator) and from client to server. But I want to send a

  • TCP client server sampleNovember 30

    All, This may not really be a LabWindows/CVI question but I'm really stuck on what should be easy to solve. The brain trust here on the forums has always been helpful so I'll try to explain. The project: Get LabWindows/CVI code talking to a muRata SN

  • Not able to run the client programOctober 11

    I have written a simple example to print a string using EJB on weblogic 6.0 I have written a simple RMI client program . when i run that program it is throwing an remote exception saying that connection refused to host.. pls help me redgs aaag555Have

  • How to program the simple tcp/ip connection?November 30

    I would like to know how to program in labview the simple tcp/ip connetion. And is there some site with examples.Luciano Kan Horiuchi wrote: > I would like to know how to program in labview the simple tcp/ip connetion. > And is there some site with

  • Problems with a simple stop watch programOctober 11

    I would appreciate help sorting out a problem with a simple stop watch program. The problem is that it throws up inappropriate values. For example, the first time I ran it today it showed the best time at 19 seconds before the actual time had reached

  • Problem while running client program in Netbeans4.0October 11

    Hi, I am facing the following problem while running a client program in Nebeans4.0. An unexpected exception has been detected in native code outside the VM. Unexpected Signal : EXCEPTION_ACCESS_VIOLATION (0xc0000005) occurred at PC=0x7C9012B4 Functio

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 1.161 s.