• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

sockets

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hey guys i m new to java programming. i have jdk1.6. i started on socket programming. here is the code for it
server side:

import java.io.*;
import java.net.*;
class server
{
public static void main(String[] args)
{
ServerSocket ss=new ServerSocket(5000);
Socket soc1=ss.accept();
DataInputStream in=new DataInputStream(soc1.getInputStream());
DataOutputStream out=new DataOutputStream(soc1.getOutputStream());
String msg=soc1.readUTF();
System.out.println(msg);
soc1.writeUTF("I received");
msg=soc1.readUTF();
soc1.close();
}
}

client side:

import java.io.*;
import java.net.*;
class client
{
public static void main(String[] args)
{
Socket soc=new Socket("192.168.1.2",5000);
DataInputStream in1=new DataInputStream(soc.getInputStream());
DataOutputStream out1=new DataOutputStream(soc.getOutputStream());
String mes="hi";
soc.writeUTF(mes);
String msg1=soc.readUTF();
soc.writeUTF("Bye");
soc.close();
}
}

i got the errors in read and write utf saying that cannot find the symbol. is my program correct or do i need an additional software along with jdk to run this kind of program.
p.s: this is a part of my project. so any help wil be highly appreciated... thank ya..

 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should spend a minute with our FAQ, How to Ask Questions on JavaRanch, in particular the sections UseCodeTags and IsolateTheProblem. The better question you ask, the more help we can give.
 
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ask yourself this: how are you using the in/out and in1/out1 fields?
 
vinod nar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ok. my program shud do this
client:hi.
server:i received.
client:bye.

this s wat the prog shud do..
 
Ulf Dittmer
Rancher
Posts: 43027
76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That doesn't address the question I proposed. Pay attention to the details of your code :-)
 
Sheriff
Posts: 22510
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

vinod nar wrote:ok. my program shud do this
client:hi.
server:i received.
client:bye.

this s wat the prog shud do..


Please UseRealWords. We do not accept "shud" and "this s wat".
 
vinod nar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
dude could you possibly change the code so that the output of the program is as i mentioned before. thanks once again
 
Rob Spoor
Sheriff
Posts: 22510
122
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would start by calling flush() after writing the data.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic