Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Convert to C: import java.io.*; import java.net.*; import java.sql.Timestamp; import java.util.*; public class UdpClient { private final static int PACKET_SIZE = 1024; private final static

Convert to C:

import java.io.*; import java.net.*; import java.sql.Timestamp; import java.util.*; public class UdpClient { private final static int PACKET_SIZE = 1024; private final static int TIME_OUT = 500; // 500 milliseconds private final static int GROUP_PORT = 5555;// reserved for broadcasting private final static String GROUP_IP = "239.255.255.255"; private int serverPort; private int clientPort; private String nickname; private InetAddress serverIp; private DatagramSocket clientSocket; private ArrayList clients; private MulticastSocket groupSocket; // to listen to server's broadcasting private ReceiverThread receiver; private SenderThread sender; private String reg = "Registration Request."; private String dereg = "Logout."; private String save = "Save Message."; private String send = "Send."; private String sendack = "Send Ack."; private String rec; // for client to client communication private InetAddress senderIp; private int senderPort; private String mmmmessage; private boolean status; private String command; public UdpClient(String nick, InetAddress ip, int sp, int cp) throws IOException { serverPort = sp; clientPort = cp; nickname = nick; serverIp = ip; clients = new ArrayList(); command = new String(); clientSocket = new DatagramSocket(clientPort); sender = new SenderThread(); receiver = new ReceiverThread(); sender.start(); receiver.start(); } public boolean checkReceiver() { if (receiver.stopped) { return false; } return true; } public void register() throws IOException, InterruptedException { // Registers the client to the server // Always times out with the server for 500 msecs * 5 command = reg; sender.sregister(); } public void runSender() { sender.run(); } public void displayTable() { // Display the local table System.out.println("[Table of Clients.]"); System.out.println(" -  -  - "); for (int k = 0; k < clients.size(); k++) { System.out.print(clients.get(k).getNickname() + " - "); System.out.print(clients.get(k).getIp() + " - "); System.out.print(clients.get(k).getPort() + " - "); if (clients.get(k).getStatus()) { System.out.println("online "); } else { System.out.println("offline "); } } } public void deregister() throws IOException, InterruptedException { // Logs out the client from the server command = dereg; sender.sderegister(); } public void sendMsg(String name, String msg) throws IOException, InterruptedException { rec = name; mmmmessage = msg; command = send; sender.ssendMsg(name, msg); } public void close() { clientSocket.close(); } private boolean stringToTable(String msg) throws UnknownHostException { // Parses the input string of table contents of clients and // fills the local client table accordingly. //  ;  ;  ;  / if (msg.isEmpty() || msg.equals("/")) { return false; } String dUsers = "[/]+"; // per user String delims = "[;]+"; // per field msg = msg.substring(1); String[] tokens = msg.split(dUsers); clients.clear(); for (int i = 0; i < tokens.length; i++) { String userString = tokens[i]; String[] fields = userString.split(delims); InetAddress ip = InetAddress.getByName(fields[0]); String nickname = fields[1]; int port = Integer.parseInt(fields[2]); boolean status = true; if (fields[3].equals("false")) { status = false; } User user = new User(ip, nickname, port, status); clients.add(user); } return true; } private void extractMsgs(String msg) { // Extracts each message from the received string and displays the conversation //  ; 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

1 2 3 Data Base Techniques

Authors: Dick Andersen

1st Edition

0880223464, 978-0880223461

More Books

Students also viewed these Databases questions