Tag » Client-server

VB.Net Server Client

‘Server Code:
‘Code:

Imports System.Net, System.Net.Sockets
Public Class frmServer
Dim server As Socket
Dim client As Socket
Dim bytes As Byte() = New Byte(1023) {} 265 kata lagi

Socket Programming

VB.Net Multi-Client Server Socket

‘Server

Imports System.Net, System.Net.Sockets
Public Class frmServer
Dim serverSocket As Socket
Dim clientSocket As Socket

Private Sub frmServer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load… 352 kata lagi

Socket Programming

Journey to the Center of the Plant, from FIELD to SCADA and Back! Part 3 – SCADA Software

­Now it’s time to create your SCADA software, in Part 2 we continued following our tank temperature from being a physical variable until it reached our computer in the form of a  1.181 kata lagi

SCADA

Questions and Answers Java Sockets

/**Questions and Answers  
 * 
 *Java implementation to communicate between client and server 
programs that ask and, respectively, answers the predefined questions */

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

public class ServerAnswers {

	private ServerSocket serverSocket;

	public ServerAnswers(int port) throws IOException {
		serverSocket = new ServerSocket(port);
	}

	
	public void handleConnections()
	{
		while (true)
		{
			try {
				System.out.println("Waiting for client on port " +
						serverSocket.getLocalPort() + "...");
				Socket socket = serverSocket.accept();
				QuestionsThread questions = new QuestionsThread(socket);
				// Open new thread to handle new client
				questions.start();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

	public static void main(String[] args) throws IOException {
		ServerAnswers server = new ServerAnswers(1500);
		//create new server that listen on port 1500
		server.handleConnections();
	}
}

public class QuestionsThread extends Thread {

	Socket socket;

	public QuestionsThread(Socket socket) {
		this.socket = socket;
	}

	public void run() {
		System.out.println("Just connected to "
				+ socket.getRemoteSocketAddress());
		while (true) {
			try {
				InputStream inFromClient = socket.getInputStream();
				DataInputStream in =
						new DataInputStream(inFromClient);
				OutputStream outToClient = socket.getOutputStream();
				DataOutputStream out =
						new DataOutputStream(outToClient);
				String receivedMessage = in.readUTF();
				System.out.println("receivedMessage: " + receivedMessage);
				if(receivedMessage.equals("Bye")){
					socket.close();
					break;
				}
				String answer;
				switch (receivedMessage) {
				case "What are you doing?": {
					answer = "I am fine";
					break;
				}
				case "How is the weather?": {
					answer = "It's sunny";
					break;
				}
				default: {
					answer = "I don't know";
				}
				}
				out.writeUTF(answer);
				System.out.println(answer);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}


public class ClientQuestions {

	public ClientQuestions() {
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String serverIPAddress = "localhost";
		int serverPort = 1500;
		try {
			Socket clientSocket = new Socket(serverIPAddress, serverPort);
			System.out.println("Connected to server :" + clientSocket.getRemoteSocketAddress());
			OutputStream outToServer = clientSocket.getOutputStream();
			DataOutputStream out =
					new DataOutputStream(outToServer);
			InputStream inFromServer = clientSocket.getInputStream();
			DataInputStream in =
					new DataInputStream(inFromServer);

			BufferedReader bufferRead;
			String command;
			while (true) {
				bufferRead = new BufferedReader(new InputStreamReader(
						System.in));
				command = bufferRead.readLine();
				out.writeUTF(command);
				System.out.println(command);
				if (command.equals("Bye")) {
					break;
				}
				System.out.println("This is what Server replied: " + in.readUTF());
			}
			out.writeUTF(command);
			clientSocket.close();

		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

Java

PHP: How to create and delete directories + uploading a file

It can be very useful when creating a home page for a registered user to add extra features such as creating a new directory which will create a new folder in the location where our PHP files are saved,  deleting an existing directory will delete this folder and finally uploading a file will allow users to upload a file saved in their computers into the page. 366 kata lagi

IT

Security issues in Second Life

Security issues have always been an important point of discussion within virtual worlds, these include both: ethical and legal implications. Second Life is no exception, it is easier to see nowadays a link between the virtual world and the real world, for example financial data to virtual economies or the boundaries to real life and the virtual world are sometimes not clear. 393 kata lagi

IT

Creating An Android Application with MIT App inventor

Creating a simple android app becomes very easy thanks to MIT App Inventor by Android. It is available from their website and it provides the user with a simple menu which allows developers to start a new project, delete a project and to publish it. 459 kata lagi

IT