• 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 ...
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown

Java client socket to talk to C server socket

Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am trying to write java client-socket to talk to C server-socket.
my application does not read from the server, though it send over the data from the client in the first run. when I try to run in again is just hanhs. Here is my code, please help.

import java.io.*;
import java.net.*;

public class db_connect {

public static void main(String[] args) throws IOException {

Socket socket = null;
PrintStream out = null;
BufferedInputStream in = null;

String msg_out = "1234";
byte[] bytes = msg_out.getBytes();

try {
socket = new Socket( "ip", port);
out = new PrintStream(socket.getOutputStream());
in = new BufferedInputStream(socket.getInputStream());

} catch (UnknownHostException e) {
System.err.println("Don't know about host: hostname");

} catch (IOException e) {
System.err.println("Couldn't get I/O for the on :hostname");

if (socket != null) {
try {

out.write(bytes, 0, bytes.length); //sends data to server

int c;
while ((c = in.read()) !=-1){


} catch (UnknownHostException e) {
System.err.println("Trying to connect to unknown host: " + e);
} catch (IOException e) {
System.err.println("IOException: " + e);

[ September 15, 2004: Message edited by: Sewsew ]
[ September 15, 2004: Message edited by: Sewsew ]
    Bookmark Topic Watch Topic
  • New Topic