Solved

Socket Communication Java to C

Posted on 1998-08-31
6
236 Views
Last Modified: 2008-03-17
Server program written in C, which has got lot of structures.  I have to write the client program in JAVA.?  How can I do it.?  Any approach.?  Any examples.?
0
Comment
Question by:Arumugam
6 Comments
 

Author Comment

by:Arumugam
ID: 1223073
It is very very urgent.   Expecting answer as soon as possible.  Thanks in advance for the help.  
0
 
LVL 3

Expert Comment

by:sailwind
ID: 1223074
It shouldn't really matter what language the server's written in. As long
as you know what the data in the packet that it sends you and what it
expects, it should work perfectly fine.
0
 

Accepted Solution

by:
dys earned 50 total points
ID: 1223075
Arumuqam:
   Just as sailwind say,No matter what language the server and client programs,only the method of communication server and client is same.if server uses Datastream,the client must use Datastream,is server users Datapacket,the client must use Datapacket.So you must know your server use what method and host address and  port by server using.
      The example of client program in JAVA(the method of communication is datastream):
        import java.net.*;
      import java.applet.*;
      import java.io.*;
      public class Client extends Applet
      {
            DataInputStream dis;
            BufferedInputStream bis;
            InputStream is;
            String s;
            Socket sc;
            public void init(){
            sc=new Socket("hostname or hostIP",server_port);
            is=sc.getInputStream();
            bis=new BufferedInputStream(is);
            dis=new DataInputStream(bis);
            }

            public void start(){
            while(true){
                  //read line from socket port:sc
            s=dis.readLine();
            ...
            ...
            }
      }

0
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 

Author Comment

by:Arumugam
ID: 1223076
I agree to you.. can you clear this point.
Server is expecting a structure in the form of "integer, unsigned short, string" at one time.  How to send this data to the server.?  So that server will take that and respond for me.  Hope you know that, unsigned short is 16-bit in C and 32-Bit in JAVA.  

0
 

Author Comment

by:Arumugam
ID: 1223077
Can you clear this point..  I agree to your answer.
Assume that server expecting a buffer which contains "integer, unsigned short, string".  How the client has to send that buffer in order to take care of unsigned short value.  (because unsigned short value is 16-Bit in C and 32-Bit in Java).
0
 
LVL 8

Expert Comment

by:diakov
ID: 1223078
Another concern is the byte ordering, Little Endian or Big Endian. Mac machines use different from the PCs. You have to use byte sequences since they are universal. Thus, convert the data types to the expected amount of bytes in the order you think they should be and then the string should be zero terminated. I believe that the first two bytes (or four) of the structure are the size of the structure it self. So be carefull, because the server probably reads data in chunks of n (2 bytes), and then n bytes, then again n(2 bytes), and so on.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
MySqlDump not dumping triggers 1 43
Error in @AspectJ Based AOP with Spring 2 18
sql import cannot be resolved jsp 3 48
junit as external jar or library 7 23
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question