Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System
- Imports System.Net
- Imports System.Net.Sockets
- Imports System.Text
- Public Module Module1
- Private IPAddress As IPAddress = IPAddress.Parse("10.0.0.100")
- Private IPEndPoint As New IPEndPoint(IPAddress, 11000)
- Private Socket As Socket = Nothing
- Public Sub Main()
- Try
- Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)
- If Not IsNothing(Socket) Then
- Socket.Bind(IPEndPoint)
- Socket.Listen(10)
- While (True)
- Dim handler As Socket = Socket.Accept()
- Dim data As String = ""
- While (True)
- Dim bytes(handler.ReceiveBufferSize) As Byte
- Dim bytesRec As Integer = handler.Receive(bytes)
- data = Encoding.ASCII.GetString(bytes, 0, bytesRec)
- If data.Length > 0 Then
- Exit While
- End If
- End While
- Console.WriteLine("Mensagem recebida: " & data & "")
- handler.Shutdown(SocketShutdown.Both)
- handler.Close()
- End While
- End If
- Catch ex As Exception
- End Try
- End Sub
- End Module
- package com.pcriot.maxsoft.testapp;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.net.Socket;
- import android.os.Bundle;
- import android.widget.TextView;
- import android.app.Activity;
- public class MainActivity extends Activity {
- private TextView LabelStatus = null;
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- LabelStatus = (TextView)findViewById(R.id.LabelStatus);
- Thread thread = new Thread(new Runnable() {
- public void run() {
- try {
- Socket socket = new Socket("10.0.0.100", 11000);
- DataInputStream DIStream = new DataInputStream(socket.getInputStream());
- DataOutputStream DOStream = new DataOutputStream(socket.getOutputStream());
- String msg = "teste";
- DOStream.write(msg.getBytes(), 0, msg.getBytes().length);
- DOStream.flush();
- String text = DIStream.readLine();
- LabelStatus.setText(text);
- DOStream.close();
- DIStream.close();
- socket.close();
- } catch (Exception e) {
- LabelStatus.setText(e.toString());
- }
- }
- });
- thread.start();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement