I'm writing a bluetooth related application, and I'm using a API called BlueCove if you're familiar with it.
I managed to send some text from the client to a server, however I'm not familiar with the API for sending information from a server to a client so I couldn't send any information back to the client. I want to know how to do that.
Could anyone point me to it? I'm really unfamiliar with the API. Thanks
Turns out to be a really simple thing. Bluetooth provides different ways to communicate between devices, and one of them is using DataStream. Set up the following on both server and client side, and they'll be able to talk to each other:
StreamConnection conn = (StreamConnection)Connector.open(url);
DataOutputStream output= new DataOutputStream(conn.openOutputStream());
DataInputStream input = new DataInputStream(conn.openInputStream());
Whatever is put in DataOutputStream on one end, it'll come out in DataInputStream on the other side of the connection, regardless whether it's a server/client. DataInputStream and DataOutputSream's API are found in the link.
Related
I would like to use an android app to send GPS coordinates using a prepaid sim card. My theory is that if i don't download any response and i only send requests, i won't drain the card of money.
To test this: Is there a way to 1. On android; create a certain type of request that does not expect a return? 2. on the server side; (preferably php -lamp stack) not deliver a response?
I feel like it would be something to do with UDP versus TCP.
HTTP typically runs over TCP. If you wrote a client server model that uses UDP or some sort of hybrid approach instead, then this could work. While I am by no means an expert, I don't know of any commonly used RESTful applications that run over UDP.
Creating a socket connection to your server and writing using UDP protocol will do the trick as Steve explain above
Here what i did similiar without responce
InetAddress serverAddr = Inet4Address.getByName("addressIP");
Socket socket = new Socket(serverAddr, SERVERPORT);
socket.getOutputStream().write("your data".getBytes());
Where SERVERPORT stands for 8080,4040 anything depends on your server. I Used this piece of code to communicate with Server
I am trying to learn how to make a multiple-client chatting program. Im following the Oracle tutorial on Custom Networking, but its not really what I am looking for. So far, I have no code of my own to share, all of it is copied from the Oracle tutorial and I think pasting it here would be a copyright infringement(??).
link at: http://docs.oracle.com/javase/tutorial/networking/sockets/clientServer.html+
client code link: http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/networking/sockets/examples/KnockKnockClient.java
anyway, I have the server-client working where the server tells knock knock jokes, the client reads and prints, then the user replies and so on. how would i start to edit it to have the client talk to the other clients directly?
im sorry, i have no background with networking at all. if anyone can direct me to a informative source better suited to my goals i would appreciate it.
as in the Knock-Knock example, each client connects to the server, but they not mutually directly connected.
There is a solution to make a forwarding sever :Arrange each client an id, and clients use id to identify their talking partners.
To do this, you have to modify the client to server data format from a plain string to a tuple like (String,Id). And, when the server receive the data, it parses out the id, get the corresponding client socket and then write the data.
The required level of complexity just went up a notch as your going to need some sort of "interprocess communications" infrastructure to allow client to client communication (possibly via sockets marshalled by the server?)
I have an SMS-based Java application using CommV3 drivers for Serial communication to a GSM Modem. I have two separate codes, one for sending messages and one for receiving messages. Each code works perfectly when executed individually.
Now, when I want to integrate both these codes, I get a PortInUseException, which might be obvious. But, I am not sure where to start from.
Could I get pointers/ links/ tutorials where I could start resolving my issue. I do not have a clue where I should start from.
Thanks in advance!
Make sure that your code uses one SerialPort and not two. Then there is no problem reading or writing to this port.
SerialPort serialPort;
InputStream inStream;
OutputStream outStream;
serialPort = (SerialPort) portId.open(...);
serialPort.setFlowControlMode(...);
serialPort.setSerialPortParams(...);
inStream = serialPort.getInputStream ();
outStream = serialPort.getOutputStream ();
PS: SMSLib is an excellent Java library (ported to .NET Framework as well) which allows you to send/receive SMS messages via a compatible GSM modem or GSM phone. SMSLib also supports some bulk SMS operators. It is free and very stable.
Probably you can separate out the listener code (which binds to a port) from 2 codes .
and dedicate to the appropriate code segment based on send / recieve.
I am trying to send an image from the android phone, process it on the server side, and then get it back to the phone. I have been able to send the file from the phone to the server but then it seems that the server cannot send the image using the same socket. I am using bufferedinputstream and bufferedoutputsteram. is it possible or would i need 2 different ports? code is in java.
It is possible to have a 2-way-communication by using one socket connection.
In easy words: the server's outputstream is the client's inputstream and vice versa.
I have a university project which is already 99% completed. It consists of two parts-website (PHP) and desktop (Java).
People have their accounts on the website and they wish to query different information regarding their accounts. They send an SMS which is received by desktop application which queries database of website (MySQL) and sends the reply accordingly. This part is working superbly. The problem is that some times website wishes to instruct the desktop application to send a specific SMS to a particular number. Apparently there seems no way other than putting all the load to the DB server... This is how I made it work. Website puts SMS jobs in a specific table. Java application polls this table again and again and if it finds a job, it executes it. Even this part is working correctly but unfortunately it is not acceptable by my university to poll the DB like this. :(
The other approach I could think of is to use client-server one. I tried making Java server and its PHP client. So that whenever an SMS is to be sent, the website opens a socket connection to desktop application and sends two strings (cell # and SMS message). Unfortunately I am unable to do this. I was successfully to make a Java server which works fine when connected by a Java client, similarly my PHP client connects correctly to a PHP server, but when I try to cross them, they start hating each other... PHP shows no error but Java gives StreamCorruptedException when it tries to read header of input stream.
Could someone please tell what I can try to make PHP client and Java server work together? Or if the said purpose can be achieved by another means, how?
Regards,
Yasir
Wait... are you using object streams? According to the java documentation StreamCorruptedException is "Thrown when control information that was read from an object stream violates internal consistency checks." I doubt your PHP app is sending what Java considers a serialized object. Why don't you go low-tech and read a string? The following had worked for me back in the day:
ServerSocket serverSocket = new ServerSocket(port);
Socket clientSocket = serverSocket.accept();
BufferedReader in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
while((inputLine = in.readLine())!=null)
{
//Do whatever
}
You might try looking into Quercus. It's a server that runs PHP inside java. You can call java called directly from PHP as if it was native PHP functions. You won't have to worry about streams then.