Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

How to Store values from datagrams

  Asked By: Elliott    Date: Aug 04    Category: Java    Views: 873
  

I appreciate all the help given by the members of this forum.Thanks
people.
iam developing a chat server.I need to extract the
Username ,ClientIPaddress ,ClientPortNumber from various clients and
store them in a array.How can i do this?
In this program the datagram recieved by the server contains the
login, ipaddress and port no .How can i put them in a array? what
method should i be using to extract the info?? can sombody help?

----------------------------------------------------
import java.io.*;
import java.net.*;

class UDPServer1
{
public static void main(String args[]) throws Exception
{
String Ctrl1;
DatagramSocket serverSocket = new DatagramSocket
(9876);
byte[] receiveData = new byte[1024];
byte[] sendData = new byte[1024];
while ( true )
{

DatagramPacket receivePacket = new
DatagramPacket(receiveData,receiveData.length);
serverSocket.receive(receivePacket);

String sentence = new String
(receivePacket.getData(),"ASCII");
//String login[] = new String(sentence);
for(int i =0;i>=login.length;i++)
{
if(login[i].equals(login[i+1]))
{
Ctrl1="UnSuccessful" ;
}
else
{
Ctrl1 ="Sucess" ;
}
};
InetAddress IPAddress =
receivePacket.getAddress();
System.out.println(IPAddress);

int port = receivePacket.getPort();

sendData = Ctrl1.getBytes();
DatagramPacket sendPacket = new
DatagramPacket(sendData,sendData.length,IPAddress,port);
serverSocket.send(sendPacket);

}
}
}

Share: 

 

No Answers Found. Be the First, To Post Answer.

 
Didn't find what you were looking for? Find more on How to Store values from datagrams Or get search suggestion and latest updates.




Tagged: