Client-Server Communication in C: Examples and Code
Client Program Example (AF_INET, Stream)
This is an example of a client program using the AF_INET
family type and stream sockets that sends messages to a server program. The functions leer_linea
and escribir_linea
are assumed to be defined in the file comun.c
.
void escribir_mensaje(int s);
int main() {
int sd;
struct sockaddr_in dirser;
if ((sd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
perror("Error creating socket");
return 1;
}
dirser.sin_family = AF_INET;
Read More
Java AWT Components: Buttons, Lists, Text Fields, and More
Buttons
Buttons can be created with objects using the operator new:
Button button; button = new Button("Button");
Used in CADNA creation, the button will appear when displayed on the screen. This is also what CADNA will return to use when identifying the button event.
Button Events
One-touch button events can be captured by overloading the method action():
public boolean action(Event evt, Object obj) {
if (evt.target instanceof Button)
System.out.println((String) obj);
else
Database Schema and Queries for Hockey League
Table Structures
Equipo Table
— Table structure for table Equipo
DROP TABLE IF EXISTS Equipo
;
CREATE TABLE Equipo
(
team_id
int(11) NOT NULL,
teamName
varchar(45) DEFAULT NULL,
PRIMARY KEY (team_id
)
Estadísticas_Equipo Table
— Table structure for table Estadísticas_Equipo
DROP TABLE IF EXISTS Estadísticas_Equipo
;
CREATE TABLE Estadísticas_Equipo
(
game_id
int(11) NOT NULL,
team_id
int(11) NOT NULL,
tgoals
int(11) DEFAULT NULL,
tshots
int(11) DEFAULT NULL,
thits
int(11) DEFAULT NULL,
PRIMARY KEY (game_id
,team_
Java Person and Pet Management Code
Java Person and Pet Management
This Java code provides functionality to manage a list of people and their pets. It includes methods to create, read, update, and delete person records.
Create Person
The createPerson()
method allows you to add a new person to the list. It prompts for the person’s name, age, and gender, and allows adding pets to the person’s record.
public static void createPerson() {
String name = WordNotEmpty("Enter name:");
if (getPersonByName(name) != null) {
System.
Read More
Firewall Technologies: Packet Filtering, Proxy, and Stateful Inspection
Firewall Technologies
Packet filtering – Packets (small chunks of data) are analyzed against a set of filters. Packets that pass the filters are sent to the requesting system; all others are discarded.
Proxy service – Information from the Internet is retrieved by the firewall and then sent to the requesting system and vice versa.
Stateful inspection – A newer method that doesn’t examine the contents of each packet but instead compares certain key parts of the packet to a database of trusted information.
Read MoreJava Code Snippets: Database, Lambda, and String Operations
Database URL: jdbc:mysql://mis-sql.uhcl.edu/agarwaln8497
agarwaln8497
1005681
String errorMsg = "";
Connection c = null;
Statement s = null;
ResultSet rset = null;
Submit Method
This method handles database connection and data retrieval.
public String Submit() {
try {
Class.forName("com.mysql.jdbc.Driver");
System.out.println("Driver is ok.");
} catch (ClassNotFoundException