Click here to Skip to main content
15,922,533 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Dear all,

I am working on a project which involves send messages and receive message/ through GPRS modem /modem to a specified server port(having static IP).

I need Java code to send data through GPRS modem to server's specified port. If anyone having experience in this area please guide me.

Thanks,

What I have tried:

Java
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("localhost");
byte[] sendData = new byte[256];
byte[] receiveData = new byte[256];
                
String sentence = inFromUser.readLine();
sendData = sentence.getBytes();
DatagramPacket sendPacket1 = new DatagramPacket(sendData, sendData.length, IPAddress, 1500);
clientSocket.send(sendPacket1);
               
DatagramPacket receivePacket1 = new DatagramPacket(receiveData, receiveData.length);
clientSocket.receive(receivePacket1);
sentence = receivePacket1.getData().toString();
System.out.println("Received1:"+sentence+":"+"ip Address"+receivePacket1.getAddress()+":"+"port:"+receivePacket1.getPort());
System.out.println("FROM SERVER1:" +sentence);
Posted
Updated 19-Aug-16 22:33pm
v3
Comments
Richard MacCutchan 20-Aug-16 4:33am    
So what is the problem?
Member 12694440 20-Aug-16 4:50am    
I want to communicate with devices but I did not get any data from devices ,
I am not receiving data from devices and devices is on .I am using port and IP to communicate with devices I need to help for communicating with mulktiple devices as well as single devices. so we have to do for this

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900