Italian Chat tramite TCP

lo_sty

Member
Salve , ho realizzato una chat in vb.net che usa la trasmissione dati tramite TCP tra più dispositivi . Ora vorrei sapere se è possibile crearne un app che si colleghi all'ip e port da me impostate per a comunicazione ed inviare e ricevere messaggi
 

Spinter

Active Member
Licensed User
lato server

B4X:
Sub Process_Globals  
    Dim AStreams As AsyncStreams 
    Dim Server As ServerSocket
    Dim Socket1 As Socket
    Dim myport As String
    Dim ServerIp As String
  
   
End Sub
Sub Globals

    Dim Button1 As Button
    Dim btnConnect As Button
    Dim btnDisconnect As Button
    Dim EditText1 As EditText
    Dim EditText2 As EditText
End Sub

Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("1")  
myport = 10108
ServerIp="0.0.0.0"

End Sub

Sub btnConnect_Click
Try
Socket1.Initialize("Socket1")
Socket1.Connect(ServerIp ,myport, 20000)
Catch 
ToastMessageShow( "Non conesso", True)
End Try
End Sub


Sub Socket1_Connected (Connected  As Boolean)
   If Connected = True Then 
        ToastMessageShow( "Connesso", True)
           AStreams.Initialize(Socket1.InputStream,Socket1.OutputStream,"Astreams")
    End If
End Sub




Sub send_data(data As String)

If AStreams.IsInitialized = True Then 
    Dim buffer() As Byte     
        data=data
        buffer = data.GetBytes("UTF8")  
        AStreams.Write(buffer)   
      End If
End Sub

Sub AStreams_NewData (Buffer() As Byte)
Dim msg As String
msg = BytesToString(Buffer, 0, Buffer.Length, "UTF8")
EditText2.Text=""
EditText2.Text=msg
End Sub

Sub AStreams_Error 
ToastMessageShow( LastException.Message, True)
End Sub

Sub Button1_Click
     send_data("test")
End Sub

Scopiazza un po'!!
 

lo_sty

Member
Grazie per la risposta .
Il lato server me lo fa il programma in VB.Net , a me serve lato client ma credo di riuscire col codice da te postato .
Grazie
 
Top