Solved

Socket Communication Java to C

Posted on 1998-08-31
6
239 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This video teaches viewers about errors in exception handling.

734 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