Verbindung übers Internet

Anfängerfragen zum Programmieren mit PureBasic.
Benutzeravatar
KeyKon
Beiträge: 1412
Registriert: 10.09.2004 20:51
Computerausstattung: Laptop: i5 2,8 Ghz, 16GB DDR3 RAM, GeForce 555GT 2GB VRAM
PC: i7 4,3 Ghz, 32GB DDR3 RAM, GeForce 680 GTX 4GB VRAM
Win10 x64 Home/Prof
PB 5.30 (64bit)
Wohnort: Ansbach
Kontaktdaten:

Verbindung übers Internet

Beitrag von KeyKon »

Wie kann ich mit PB übers Internet ne Verbindung zu einem Anderen PC aufbauen?

KeyKon
(\/) (°,,,°) (\/)
Benutzeravatar
Laurin
Beiträge: 1639
Registriert: 23.09.2004 18:04
Wohnort: /dev/eth0

Beitrag von Laurin »

Schau dir in der Hilfe mal das Kapitel 'Network' an. Da findest du alles,w as du brauchst ;)
Now these points of data make a beautiful line.
And we're out of beta. We're releasing on time.
Benutzeravatar
KeyKon
Beiträge: 1412
Registriert: 10.09.2004 20:51
Computerausstattung: Laptop: i5 2,8 Ghz, 16GB DDR3 RAM, GeForce 555GT 2GB VRAM
PC: i7 4,3 Ghz, 32GB DDR3 RAM, GeForce 680 GTX 4GB VRAM
Win10 x64 Home/Prof
PB 5.30 (64bit)
Wohnort: Ansbach
Kontaktdaten:

Beitrag von KeyKon »

OK, geht das dann wohl so wie über LAN?
Aber wie komme ich an die IP die mein PC im Internet hat und welchen Port muss ich verwenden?

KeyKon
(\/) (°,,,°) (\/)
Jake
Beiträge: 121
Registriert: 28.05.2005 04:10
Wohnort: Berlin

Beitrag von Jake »

Deine IP bekommst du von einer Internetseite wie z.B. http://checkip.dyndns.org
Wie du das auswertest steht hier:
http://forums.purebasic.com/german/view ... +ermitteln
MfG Jake
Benutzeravatar
Laurin
Beiträge: 1639
Registriert: 23.09.2004 18:04
Wohnort: /dev/eth0

Beitrag von Laurin »

KeyKon hat geschrieben:OK, geht das dann wohl so wie über LAN?
Ja. Intra- und Internet funktionieren auf nahezu gleicher Art.
Aber wie komme ich an die IP die mein PC im Internet hat und welchen Port muss ich verwenden?
Der Port ist dir überlassen. Du solltest nur eine Portnummer größer wie 5000 - 6000 wählen. Die 'kleineren' Ports sind öfters schon von anderen Programmen belegt.

Greetz Laurin
Now these points of data make a beautiful line.
And we're out of beta. We're releasing on time.
Benutzeravatar
KeyKon
Beiträge: 1412
Registriert: 10.09.2004 20:51
Computerausstattung: Laptop: i5 2,8 Ghz, 16GB DDR3 RAM, GeForce 555GT 2GB VRAM
PC: i7 4,3 Ghz, 32GB DDR3 RAM, GeForce 680 GTX 4GB VRAM
Win10 x64 Home/Prof
PB 5.30 (64bit)
Wohnort: Ansbach
Kontaktdaten:

Beitrag von KeyKon »

Warum geht das dann nicht:

Code: Alles auswählen

;Server

If InitNetwork() = 0
  Debug "Init Network Error"
  End
EndIf
If CreateNetworkServer(5656) = 0
  Debug "Create Server Error"
  End
EndIf

Repeat
  Delay(10)
  If NetworkServerEvent() = 1
    Debug "New Client!"
  EndIf
ForEver

Code: Alles auswählen

;Client

If InitNetwork() = 0
  Debug "Init Network Error"
  End
EndIf
If OpenNetworkConnection("IP",5656) = 0
  Debug "Open Connection Error"
  End
Else
  Debug "Connected!!!"
  Delay(1000)
  End
EndIf
:freak:

KeyKon
(\/) (°,,,°) (\/)
Benutzeravatar
Macros
Beiträge: 1361
Registriert: 23.12.2005 15:00
Wohnort: Olching(bei FFB)
Kontaktdaten:

Beitrag von Macros »

zwei Sachen:
erster Fehler: nimm mal das Delay beim Server raus,
ich hab auch mal so einen "Grund-Server" zu Testzwecken programmiert.
Der hat nichts angenommen, bis ich das Delay rausgenommen hab.
(Als dann 600 Zeilen Quellcode in der Schleife waren, ging auch das Delay :? )

zweiter Fehler (wenns einer ist): "IP" ich glaube nicht, dass dein Computer IP heißt.

Die Fehler sind eigentlich nur Anmerkungen, denn theoretisch müsste es klappen.
Benutzeravatar
KeyKon
Beiträge: 1412
Registriert: 10.09.2004 20:51
Computerausstattung: Laptop: i5 2,8 Ghz, 16GB DDR3 RAM, GeForce 555GT 2GB VRAM
PC: i7 4,3 Ghz, 32GB DDR3 RAM, GeForce 680 GTX 4GB VRAM
Win10 x64 Home/Prof
PB 5.30 (64bit)
Wohnort: Ansbach
Kontaktdaten:

Beitrag von KeyKon »

Das mit dem IP is mir schon klar, (Ich wollte nur sämtlichen Hobby-Hackern im Forum die Chanche nehmen meinen PC zu finden :lol: )
Aber ich probiers mal ohne Delay...

KeyKon
(\/) (°,,,°) (\/)
Benutzeravatar
KeyKon
Beiträge: 1412
Registriert: 10.09.2004 20:51
Computerausstattung: Laptop: i5 2,8 Ghz, 16GB DDR3 RAM, GeForce 555GT 2GB VRAM
PC: i7 4,3 Ghz, 32GB DDR3 RAM, GeForce 680 GTX 4GB VRAM
Win10 x64 Home/Prof
PB 5.30 (64bit)
Wohnort: Ansbach
Kontaktdaten:

Beitrag von KeyKon »

Geht auch ohne Delay nicht...
Hat jemand vielleicht noch ne andere Idee?
Oder kann jemand den Code mal mitnem Freund probieren? Vielleicht liegts ja an meinem System.

KeyKon
(\/) (°,,,°) (\/)
Benutzeravatar
roherter
Beiträge: 1407
Registriert: 10.04.2005 18:58
Kontaktdaten:

Beitrag von roherter »

Hi ,ich glaube du suchst diese api-funktion GetIpAddrTable
der code ist vb aber kann man umschreiben:

Code: Alles auswählen

'This project requires the following components:
' - a form (Form1) with a textbox (Text1, Multiline=True)
'   and a command button (Command1)
' - a module (Module1)

'in Form1:
Private Sub Command1_Click()
    Module1.Start
End Sub

'In Module1:

'******************************************************************
'Created By Verburgh Peter.
' 07-23-2001
' verburgh.peter@skynet.be
'-------------------------------------
'With this small application , you can detect the IP's installed on your computer,
'including subnet mask , BroadcastAddr..
'
'I've wrote this because i've a programm that uses the winsock control, but,
'if you have multiple ip's  installed on your pc , you could get by using the Listen
' method the wrong ip ...
'Because Winsock.Localip => detects the default ip installed on your PC ,
' and in most of the cases it could be the LAN (nic) not the WAN (nic)
'So then you have to use the Bind function ,to bind to your right ip..
'but how do you know & find that ip ?
'you can find it now by this appl.. it check's in the api.. IP Table..
'******************************************************************


Const MAX_IP = 5   'To make a buffer... i dont think you have more than 5 ip on your pc..

Type IPINFO
     dwAddr As Long   ' IP address
    dwIndex As Long '  interface index
    dwMask As Long ' subnet mask
    dwBCastAddr As Long ' broadcast address
    dwReasmSize  As Long ' assembly size
    unused1 As Integer ' not currently used
    unused2 As Integer '; not currently used
End Type

Type MIB_IPADDRTABLE
    dEntrys As Long   'number of entries in the table
    mIPInfo(MAX_IP) As IPINFO  'array of IP address entries
End Type

Type IP_Array
    mBuffer As MIB_IPADDRTABLE
    BufferLen As Long
End Type

Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetIpAddrTable Lib "IPHlpApi" (pIPAdrTable As Byte, pdwSize As Long, ByVal Sort As Long) As Long
Sub main()
Form1.Show
End Sub

'converts a Long  to a string
Public Function ConvertAddressToString(longAddr As Long) As String
    Dim myByte(3) As Byte
    Dim Cnt As Long
    CopyMemory myByte(0), longAddr, 4
    For Cnt = 0 To 3
        ConvertAddressToString = ConvertAddressToString + CStr(myByte(Cnt)) + "."
    Next Cnt
    ConvertAddressToString = Left$(ConvertAddressToString, Len(ConvertAddressToString) - 1)
End Function

Public Sub Start()
Dim Ret As Long, Tel As Long
Dim bBytes() As Byte
Dim Listing As MIB_IPADDRTABLE

Form1.Text1 = ""

On Error GoTo END1
    GetIpAddrTable ByVal 0&, Ret, True

    If Ret <= 0 Then Exit Sub
    ReDim bBytes(0 To Ret - 1) As Byte
    'retrieve the data
    GetIpAddrTable bBytes(0), Ret, False
      
    'Get the first 4 bytes to get the entry's.. ip installed
    CopyMemory Listing.dEntrys, bBytes(0), 4
    'MsgBox "IP's found : " & Listing.dEntrys    => Founded ip installed on your PC..
    Form1.Text1 = Listing.dEntrys & "   IP addresses found on your PC !!" & vbCrLf
    Form1.Text1 = Form1.Text1 & "----------------------------------------" & vbCrLf
    For Tel = 0 To Listing.dEntrys - 1
        'Copy whole structure to Listing..
       ' MsgBox bBytes(tel) & "."
        CopyMemory Listing.mIPInfo(Tel), bBytes(4 + (Tel * Len(Listing.mIPInfo(0)))), Len(Listing.mIPInfo(Tel))
         Form1.Text1 = Form1.Text1 & "IP address                   : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwAddr) & vbCrLf
         Form1.Text1 = Form1.Text1 & "IP Subnetmask            : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwMask) & vbCrLf
         Form1.Text1 = Form1.Text1 & "BroadCast IP address  : " & ConvertAddressToString(Listing.mIPInfo(Tel).dwBCastAddr) & vbCrLf
         Form1.Text1 = Form1.Text1 & "**************************************" & vbCrLf
    Next

'MsgBox ConvertAddressToString(Listing.mIPInfo(1).dwAddr)
Exit Sub
END1:
MsgBox "ERROR"
End Sub
Purebasic 5.0 32bit und 64 bit

I'm back from hell
Antworten