Socket programming help!
Hi,
i have to writte a socket file transfer client. I wrotte the code for the client and it connects to the server. But i dont know:
1. how to pass the commands ls, get and quit to the server.
2. client recognizes only small capitals but server big for example i client understands ls and server LS
anyone can help me??
thx in advance
String.toUpperCase()
String.toLowerCase()
Runtime.exec()
Similar Messages
-
SOCKET PROGRAMMING HELP NEEDED!!!!
hi,
I got an idea of establishing socket connection with all clients from SERVER through the windows command
called (arp -a). when we type the stated command on dosprompt in server, it gives the list of current system's
ipaddress.....switched on. SO i can establish socket connections in a for loop where i can take the following ipaddress from output listed from command.
i've written the code to call the command in JAVA.
i write the dosprompt output in a file named list1.txt
import java.util.*;
import java.io.*;
import java.io.File;
public class RunCommand
public static String[] runCommand(String cmd) throws IOException
ArrayList list = new ArrayList();
Process proc = Runtime.getRuntime().exec(cmd);
InputStream istr = proc.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(istr));
String str;
while ((str = br.readLine()) != null)
list.add(str);
try
proc.waitFor();
}catch (InterruptedException e)
System.err.println("process was interrupted");
// check its exit value
if (proc.exitValue() != 0)
System.err.println("exit value was non-zero");
// close stream
br.close();
// return list of strings to caller
return (String[])list.toArray(new String[0]);
public static void main(String[] args) throws Exception
try
FileWriter f1=new FileWriter("list1.txt");
String[] s = runCommand("arp -a");
for (int i = 0; i< s.length; i++)
f1.write(s);
System.out.println(s[i]);
f1.close();
}catch (Exception ex) { System.out.println(ex);}
SAMPLE OUTPUT:
Interface: 172.16.3.1 on Interface 0x1000003
Internet Address Physical Address Type
172.16.3.4 00-00-e2-13-a9-e8 dynamic
172.16.3.6 00-00-e2-13-aa-0f dynamic
172.16.3.10 00-00-e2-13-ab-bb dynamic
172.16.3.12 00-00-e2-13-ab-93 dynamic
172.16.3.16 00-00-e2-13-37-b8 dynamic
172.16.3.17 00-00-e2-13-37-19 dynamic
172.16.3.18 00-00-e2-13-37-1d dynamic
172.16.3.19 00-00-e2-13-38-98 dynamic
172.16.3.22 00-00-e2-13-37-54 dynamic
172.16.3.23 00-00-e2-13-39-02 dynamic
172.16.3.24 00-00-e2-13-39-0f dynamic
172.16.3.26 00-00-e2-13-37-a5 dynamic
172.16.3.27 00-00-e2-13-37-0b dynamic
172.16.3.28 00-00-e2-13-37-12 dynamic
172.16.3.29 00-00-e2-13-39-15 dynamic
172.16.3.30 00-00-e2-13-38-af dynamic
172.16.3.31 00-00-e2-13-37-fe dynamic
172.16.3.32 00-00-e2-13-38-ff dynamic
172.16.3.34 00-00-e2-13-ab-c8 dynamic
172.16.3.37 00-00-e2-13-ab-67 dynamic
172.16.3.42 00-00-e2-13-ab-19 dynamic
PLS HELP ME OUT IN GETTING ONLY THE IPADDRESS IN FOR LOOP IN SERVER SOCKET PROGRAM TO INVOKE ALL CLIENT'S PROGRAM IN NETWORK.
PLS HELP ME!!!!!!!
ATTACH THE CODE!!!!!!!!!!!!Connecting to a client presumes that the client is waiting for a connection.
If that is the case I would suggest looking a java.net.Socket. -
HELP : Convert socket programming from Ipv4 to IPv6
Hi all,
I need help in converting my Ipv4 socket programing to Ipv6. How can I do this? I already have an Ipv4 socket programming that is working but when I tried to convert it to Ipv6 it doesn't work .
this is my Ipv4 socket programming :
DatagramPacket sendPacket;
DatagramSocket sock;
ip = jtfDIP.getText().trim();
try{
sock = new DatagramSocket();
add = InetAddress.getByName(ip);
sendPacket = new DatagramPacket(buf,buf.length,add,port);
Please help me. How can I convert this to Ipv6. Thank you.Socket sock = new Socket("host");
or
Socket sock = new Socket("192.168.1.1");
or
Socket sock = new Socket("www.host.com");
or
Socket sock = new Socket("hhhh.hhhh.hhhh.hhhh");
Get it? Just use whatever host, domain name, or IP you need, the underlying native code does the work - you'll never need to do anything, for the most part. -
Help needed with swings for socket Programming
Im working on a Project for my MScIT on Distributed Computing...which involves socket programming(UDP)....im working on some algorithms like Token Ring, Message Passing interface, Byzantine, Clock Syncronisation...i hav almost finished working on these algorithms...but now i wanna give a good look to my programs..using swings but im very new to swings...so can anyone help me with some examples involving swings with socket programming...any reference...any help would be appreciated...please help im running out of time..
thanking u in advance
anDyhi im Anand(AnDY),
i hav lost my AnDY account..plz reply to this topic keeping me in mind :p -
Help on Server Socket Programming??????
hello Friends,
I need your help on following:
I am the only person working on this project and the company wants me to prepare a infrastructure of this project and I should also give a demo of this project to my seniors. I will breif you up with my project:
1. There is this gif image of distillation column. i will be publishing it using JApplet or Applet.
2. This Image must be seen on internet.
3. On the circle of these Image the user will click(In all there are five circles, called as controllers)and a dialog box should open thru which user will input the float values(I am using the JOptionPane class to open this dialog box).
4. The inputed values will the be given to the C program which is the simulator for distillation column.
5. The C program will generate the output through iterations(Code entirely in C), the output of each program will then be poped up to over the image beside the respective controlled or under the respective controller but definetely over the same gif file.
6. The number of iteration will depend on how fast the C program converges the inputer parameters. And each output must be show over the gif image and when the final iteration value will appear it should remain on the image until some new value is inputted by the user again by clicking on any of the circle.
The proposed theory to do this project accoding to me is as follows:
1. Since each value must be thrown to the user. I beleive this is a real time project. So I decided to use Client Server Networking technology provided by java.
2. Then I figured out that in this project there should be 2 clients One is the GUI which is the Image screen to receive the input from the user and to show the output to the user. Second client is a java program sitting behind the server which will receive this input data from user and it will have an NATIVE method through which all this input will be given to the C simulator program.
3. The middle bridge between these two clients will be a server. Which will just pass the data to and fro from both the clients.
3. The C program will perform iterations using these input values from second client. This C program will then give each iterations output to the Java program using JNI technology. This second client then sends this output value to the GUI clients through server.
Well another very important thing, I am inexperience in the field of software so I had to do a lot of R&D and this is what I found out. Frankly I am really not sure whether this is the right path to approach to this project or there is some other correct and realistic way than this? Well friends i would certainly request you if you can suggest some other simple or rather correct path or else if this is the right path then would you please suggest me the possible hiches or perticular points where I should concentrate more.
Well i am eagerly waiting for your reply.Since you are publishing your results on the net , it will be a better idea to use JSP?Servlet/Beans architecture instead of swing
I will propose a architecture as follows:
Client : Standard Browsers, IE and NS
Middle Tier: Java Webserver/Application Server
This will depend on your budget. If u have a fat allowance go for weblogic/websphere . If u are operationg on shoe string budget try for apache , etc
In the server tier code your application in the follwing architecture
JSP for presentation: Distillation towers picture, input boxes .. etc
Servlets for business logic invocation and routing requests: Your JSP submits input values to servlets, which does the processing using Java Bean Components. Since you have a lot of Logic written in C I would suggest to encapsulate these in JavaBean components using JNI technology and reuse the code.
After processing the servlet again forwards the response to another JSP for output
Advantages:
1.Your clients can be thin as most of the processing is done at the server
2. Thread Management is taken care of by your webserver, which otherwise would be a headache
3. Writing this through low level socket programming will be much more difficult as you will write your own protocol for communication this will be error prone and not scalable
If you still decide to go for traditional client server programming using swing, use RMI for communication as I insist that socket programming is very very cumbersome...using your own protocols
hope this helps
Shubhrajit -
TCP/IP socket programming in ABAP
Hi,
Is there any method of TCP socket programming in ABAP? For example is there any function module for creating a socket for a IP address and port number. After that, is it possible to send binary/text data to a connected IP/port destination. I need such a solution because I need to send raw data (native commans) to barcode printer on our network which has a static IP address and listens incoming data through a fixed port number specified in its documentation. For a solution, I coded some .NET VB and built a small application that acts as a RFC server program which can be called by SAP according to definitions I made in SM59 (I defined a new TCP connection and it works well sometimes!). In this application, data coming from SAP are transferred to the barcode printer. This is achived by the .NET Socket class library. This solution works well but after a few subsequent call from SAP, connection hangs! SAP cannot call the application anymore, I test the connection in SM59 and it also hangs, so I need to restart the VB application, but this is unacceptable in our project.
As a result, I decided to code the program that will send data to the printer in ABAP as a function module or subroutine pool, so is there any way to create a socket in ABAP and connect to specific IP/port destination? I searched for possible function modules in SE37 and possible classes in SE24 but unfortunately I could not find one. For example, do know any kind of system function in ABAP (native commands executed by CALL statement), that can be used for this purpose?
I would appreciate any help,
Kind regards,
Tolga
Edited by: Tolga Togan Duz on Dec 17, 2007 11:49 PMHi,
I doubt that there is a low level API for sockets in ABAP. There is API for HTTP but probably that won't help you. As a workaround you can use external OS commands (transactions SM69 and SM49). For example on Unix you can use netcat to transfer file. Your FM needs to dump data into folder and then call netcat to transfer file.
Cheers -
Java Swing and Socket Programming
I am making a Messenger like yahoo Messenger using Swing and Socket Programming ,Multithreading .
Is this techology feasible or i should try something else.
I want to display my messenger icon on task bar as it comes when i install and run Yahoo Messenger.
Which class i should use.I don't really have an answer to what you are asking. But I am developing the same kind of application. I am using RMI for client-server and server-server (i have distributed servers) communication and TCP/IP for client-client. So may be we might be able to help each other out. My email id is [email protected]
Are you opening a new socket for every conversation? I was wondering how to multithread a socket to reuse it for different connections, if it is possible at all.
--Poonam. -
Network and socket programming in python
i want to learn network and socket programming but i would like to do this in python.Reason behind this is that python is very simple and the only language i know .
anybody can suggest me which book should i pick.
the book should have following specification--
1)not tedious to follow
2)lots of example
3)starts with some networking stuff and then get into codes
thanks in advance with regards.hmm. well, your requirements are almost contradictory.
Not sure about books, except maybe dusty's.
Most python books cover at least some network programming (unless the book is topic specific).
I use lots of python-twisted at work. I mean ALOT. I wouldn't recommend it to someone looking for non-tedious though! I also like gevent/eventlet (esp. the async socket wrappers).
EDIT: Wow. My post wasn't really helpful at all. Sorry!
Last edited by cactus (2010-09-04 09:16:54) -
Socket Programing in J2ME - Confused with Sun Sample Code
Hai Everybody,
I have confused with sample code provided by Sun Inc , for the demo of socket programming in J2ME. I found the code in the API specification of J2ME. The code look like :-
// Create the server listening socket for port 1234
ServerSocketConnection scn =(ServerSocketConnection) Connector.open("socket://:1234");
where Connector.open() method return an interface Connection which is the base interface of ServerSocketConnection. I have confused with this line , is it is possible to cast base class object to the derived class object?
Plese help me in this regards
Thanks in advance
SulfikkarThere is nothing to be confused about. The Connector factory creates an implementation of one of the extentions of the Connection interface and returns it.
For a serversocket "socket://<port>" it will return an implementation of the ServerSocketConnection interface. You don't need to know what the implementation looks like. You'll only need to cast the Connection to a ServerSocketConnection . -
[Urgent]3G Socket programming
May I use socket for 3G networks?
I use the demo provided by the WTK2.5-Beta(NetworkDemo), it works well in the simulator. However, when I download the program to the mobile phone, it seems that the mobile phone that runs ServerSocket cannot create the socket ... all the 2 handsets use a 3G SIM card provided by a Hong Kong ISP smartTone ... What can I do?
Please help~ provide any web page of codes, thanks very much!1. We want to create a socket connection which can
remain open and live for ever till it is closed. Is
this possible in java socket programming?Yes, but it isn't practical in the real networking world. So your code had better be prepared to deal with network failures.
2. I am just wondering in order to communicate with
the third party over the socket connection, does this
other party requires to run something specific on
their end? I am not able to understand how will my
java code communicate with their server otherwise.It has nothing to do with java. Sockets send and recieve messages. The applications at either end, regardless of the language that they are written in, must handle those messages.
3. Can we send and receive data over the socket
created and also is their specific format for the
data? Yes.
Can we send files of data over this connection?Yes. (Although I don't know why you would need to do that if you are doing credit card auths.)
It would be great if someone can comment on these
questions and also if possible please provide some
code that can create socket connection.The tutorial.....
http://java.sun.com/docs/books/tutorial/networking/sockets/index.html -
Can i run UDP client and UDP server socket program in the same pc ?
hi all.
when i execute my UDP client socket program and UDP server socket program in the same pc ,
It's will shown the error msg :
"Address already in use: Cannot bind"
but if i run UDP client socket program in the remote pc and UDP server socket program run in local pc , it's will success.
anybody know what's going on ?
any help will be appreciated !bobby92 wrote:
i have use a specified port for UDP server side , and for client define the server port "DatagramSocket clientSocket= new DatagramSocket(Server_PORT);"Why? The port you provide here is not the target port. It's the local port you listen on. That's only necessary when you want other hosts to connect to you (i.e. when you're acting as a server).
The server should be using that constructor, the client should not be specifying a port.
so when i start the udp server code to listen in local pc , then when i start UDP client code in local pc ,i will get the error "Address already in use: Cannot bind"Because your client tries to bind to the same port that the server already bound to. -
Hi all,
Can I do Socket program in ABAP?
I know nothing about that,Can anyone help?
Thanks very much.
PoleWithin ABAP you have access to OLE objects - take a look at ABAB stement SET PROPERTY.
In our production we have some scale weights connected to a PC. On the PC an external vendor has created an OLE obejct that can retur te current state and weight of the scale weight directly into a SAP screen.
I guess if you can write an OLE obejct that can handle it - it is possible. -
First Very Simple Socket Program
Hello,
I am learning about Sockets and ServerSockets and how I can use the. I am trying to make the simplest server/client program possible just for my understanding before I go deper into it. I have written two programs. theserver.java and theclient.java the sere code looks like this....
import java.net.*;
import java.io.*;
import java.util.*;
public class theserver
public static void main(String[] args)
{ // IOReader r = new IOReader();
int prt = 3333;
BufferedReader in;
PrintWriter out;
ServerSocket serverSocket;
Socket clientSocket = null;
try{
serverSocket = new ServerSocket(prt); // creates the socket looking on prt (3333)
System.out.println("The Server is now running...");
while(true)
clientSocket = serverSocket.accept(); // accepts the connenction
clientSocket.getKeepAlive(); // keeps the connection alive
out = new PrintWriter(clientSocket.getOutputStream(),true);
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
if(in.ready())
System.out.println(in.readLine()); // print it
catch (IOException e) {
System.out.println("Accept failed:"+prt);
}and the client looks like this
import java.net.*;
import java.io.*;
public class theclient
public static void main(String[] args)
BufferedReader in;
PrintWriter out;
IOReader r = new IOReader();
PrintWriter sender;
Socket sock;
try{
sock = new Socket("linuxcomp",3333); // creates a new connection with the server.
sock.setKeepAlive(true); // keeps the connection alive
System.out.println("Socket is connected"); // confirms socket is connected.
System.out.println("Please enter a String");
String bob = r.readS();
out = new PrintWriter(sock.getOutputStream(),true);
out.print(bob); // write bob to the server
catch(IOException e)
System.out.println("The socket is now disconnected..");
}If you notice in the code I use a class I made called IOReader. All that class is, is a buffered reader for my System.in. (just makes it easier for me)
Ok now for my question:
When I run this program I run the server first then the client. I type "hello" into my system.in but on my server side, it prints "null" I can't figure out what I am doing wrong, if I am not converting correctly, or if the message is not ever being sent. I tried putting a while(in.read()) { System.out.println("whatever") } it never reaches a point where in.ready() == true. Kinda of agrivating. Because I am very new to sockets, I wanna aks if there is somthing wrong with my code, or if I am going about this process completely wrong. Thank you to how ever helps me,
CobbwebAn example of Creating a Client Socket (Java socket programming tutorial)
try {
InetAddress addr = InetAddress.getByName("hotdir.biz");
int port = 80;
// This constructor will block until the connection succeeds
Socket socket = new Socket(addr, port);
} catch (UnknownHostException e) {
} catch (IOException e) {
// Create a socket with a timeout
try {
InetAddress addr = InetAddress.getByName("hotdir.biz");
int port = 80;
SocketAddress sockaddr = new InetSocketAddress(addr, port);
// Create an unbound socket
Socket sock = new Socket();
// This method will block no more than timeoutMs.
// If the timeout occurs, SocketTimeoutException is thrown.
int timeoutMs = 2000; // 2 seconds
sock.connect(sockaddr, timeoutMs);
} catch (UnknownHostException e) {
} catch (SocketTimeoutException e) {
} catch (IOException e) {
}See socket tutorial here http://www.developerzone.biz/index.php?option=com_content&task=view&id=94&Itemid=36 -
N95 Maps Program Help and Suggestions Anybody??
N95 Maps Program Help and Suggestions Anybody??
havnt updated to firmware v12 yet
Why can't I search my Address or Current Location and then save this as HOME or say my Start_Point_01?
I have managed to save my HOME as a PEOPLE LOCATION and my friends address etc and worked out
how to plan a route etc, BUT Maps GPS POSITION thinks I live 20 miles away??
I dont seem to be able to simply set my HOME or Current Location myself,
I have seen some Satelite activity but insists I live 20 miles away :/ how do I fix this,
it's realy annoying. any handy tips people??
cant upgrade firmware as need phone plugged into wall socket
at webcafe, will have to wait for firmware :/
N95-1 (8GB-MicroSD),LCG-Audio,Fring,Nimbuzz,Skype,Youtube,iPlayer,Garmin4-GPS.Googlemaps,SkyFire,ZoneTag,Gravity, Sennheiser CX-400-IIs,500-IIs,TR-120 Wireless,HD215'S.AudioTechnica ATX-M50's.BT B-Tube BT Speaker.The least problems you'll have with miniDV cameras. About any miniDV camera will connect to a Mac via Firewire. HDD cameras are an open invitation to trouble, especially as you speak of older computers.
There are well-featured models out there now for 2-300 bucks. But watch out for cameras that connect to the computer via a dock. I had two Sony with these @#$% docking stations .... both docks broke and rendered the cameras useless for capturing. replacing the dock was nearly the price of a new cam. -
Socket Programming-Not getting response from server.
Hi,
I am trying to communicate with server using java socket programming, I am getting the response for first two times third time when I am trying to write some thing I am not getting any response from the server,
I am writing to migrate the vb code to Java the vb is using a c++ dll to communicate with the server and we tried accessing the dll from java using JNI then it is working fine, this dll is dependent on windows so we want to avoid the dependency with windows that is why we are going for socket programming, Please help on this.Hi,
I am writing the data in forms of string
like
Socket sockt = new Socket(ipAddress, portNo);
out= new DataOutputStream(sockt.getOutputStream());
in = new DataInputStream(sockt.getInputStream());
out.writeBytes("Serv");
out.writeBytes("Serv,32");
out.writeBytes("home,serv32,run.prg,sucess");
these are the strings to communicate with server.
I am trying to read the same
StringBuffer buf = new StringBuffer();
byte b = '\0';
try {
while ((b = in.readByte()) != '\0')
char ch = (char) b;
buf.append(ch);
} catch (Exception e) {
System.out.println(e.getStackTrace());
we are getting the response for the first two strings, but for the third string it is getting stucked for some time and returing some junk values like '???' we are sending the same string using JNI and it is working.
Maybe you are looking for
-
Should I upgrade? to - Mac OS 10.8 and / or Premiere Pro CS 6
So I'm currently on Premiere Pro 5.5.2 and Mac OS 10.7.3 The reason I have not upgraded to 10.8 is I have heard in the forums that there are problems, specifically with AVCHD and not being able to re-establish links once they are broken after import
-
I have an Envy 700 339 desktop running windows 8 I want to set up three monitors ...PC existing card has 1-dvi, 1-hdmi...monitors are samsung 27" hdmi and have dvi/hdmi in/out Do I need another card for optimum setup or am I missing something? I purc
-
ITunes crashed and now i cannot start my Macbook up
Hey, i just purchased an iPhone 4 today and upon setting it up with my iTunes, my Macbook crashed, it was totally unresponsive. So i held the power button down until it switched off. Now when i try to turn it back on it just stays at the grey apple l
-
IOTech dataplugin for DIAdem in Windows 7
Hello all.... I am using IOTech 650U, eZ-Analyst for vibration data acquisition and DIAdem 2012 for post processing and analysis. I have used IOTech dataplugin to import .dsc files into DIAdem. All this is on Windows XP. We are going to move to Windo
-
I know that there is a huge problem with apple devices not showing up in windows, which is part of the problem. However I have new problem. When I plug in the ipod shuffle to the USB port nothing at all happens. I used to plug it in and it would say