|
-
Aug 11th, 2005, 07:17 AM
#1
Thread Starter
Fanatic Member
Get ip address for the incoming client?
================================================
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim incomingdata As String
Winsock1.GetData incomingdata
Winsock1.SendData (incomingdata)
Text1.Text = incomingdata
End Sub
=================================================
when the data come in, how can i get the client ip address? or should i get the ip address in winsock1.connectrequest event? how to get?
Last edited by kenny_oh; Oct 8th, 2005 at 11:44 AM.
-
Aug 11th, 2005, 07:26 AM
#2
Re: Get ip address for the incoming client?
VB Code:
Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim incomingdata As String
Winsock1.GetData incomingdata
msgbox winsock1.remotehost
Winsock1.SendData (incomingdata)
Text1.Text = incomingdata
End Sub
-
Aug 11th, 2005, 07:37 AM
#3
Thread Starter
Fanatic Member
Re: Get ip address for the incoming client?
in the winsock1.sendData, is it possible to put the receiver ip address?
like:
winsock1.sendData(incomingdata, ipaddress) or there got another method?
-
Aug 11th, 2005, 07:48 AM
#4
Re: Get ip address for the incoming client?
winsock1.sendData(incomingdata & winsock1.localip)
-
Aug 11th, 2005, 07:57 AM
#5
Thread Starter
Fanatic Member
Re: Get ip address for the incoming client?
if the local IP change to ip address, it is winsock1.sendData(incomingdata & 127.0.0.1)
-
Aug 11th, 2005, 08:11 AM
#6
Re: Get ip address for the incoming client?
 Originally Posted by kenny_oh
if the local IP change to ip address, it is winsock1.sendData(incomingdata & 127.0.0.1)
no....
127.0.0.1 is a loopback address it isnt actually your address!
Winsock.LocalIp will return the ip of the amchine the program is being run on
winsock.RemoteHost will return the host/ip of the machine you are connected too
Pino
-
Aug 11th, 2005, 08:41 PM
#7
Thread Starter
Fanatic Member
Re: Get ip address for the incoming client?
oic.....if the server receiver the data and want to pass to another destination then the code is it like this???? pls amend my mistake!!!
winsock1.sendData(incomingdata & 192.168.1.0)
-
Aug 11th, 2005, 09:09 PM
#8
Addicted Member
Re: Get ip address for the incoming client?
 Originally Posted by kenny_oh
oic.....if the server receiver the data and want to pass to another destination then the code is it like this???? pls amend my mistake!!!
winsock1.sendData(incomingdata & 192.168.1.0)
Hmm, so what your saying is that you want to have a client send information to the server and have the server send that information to a different client? IE: A different ip address?
-
Aug 11th, 2005, 09:13 PM
#9
Thread Starter
Fanatic Member
Re: Get ip address for the incoming client?
yup........the server js act as the middle man.......when server get the data from sender it will transfer to destination....so how the to write the code?
-
Aug 12th, 2005, 03:16 AM
#10
Addicted Member
Re: Get ip address for the incoming client?
 Originally Posted by kenny_oh
yup........the server js act as the middle man.......when server get the data from sender it will transfer to destination....so how the to write the code?
Well... from the way I see it. You would have to make sure both clients are connected to the server. From there, just use the send data function with winsock. Because Client1 would send to Server, then Server would send to Client2. But without Client2 being connected the Server couldn't send any data to it. So just make sure both Clients are connected to the Server then use SendData to send the data from Client1 to Client2. I could be wrong though.. I am still kinda learning Winsock myself but I am trying to help.
-
Aug 12th, 2005, 03:24 AM
#11
Thread Starter
Fanatic Member
Re: Get ip address for the incoming client?
thank you, it help me alot..........so the code write like this?
winsock1.senddata(incmingData & 192.168.1.1)
-
Aug 12th, 2005, 04:12 AM
#12
Addicted Member
Re: Get ip address for the incoming client?
 Originally Posted by kenny_oh
thank you, it help me alot..........so the code write like this?
winsock1.senddata(incmingData & 192.168.1.1)
Umm, No.. you would have to use something like this I guess....
VB Code:
winsock1.remotehost = 192.168.1.1
winsock1.remoteport = port
winsock1.connect
If winsock1.state = sckconnected then
winsock1.senddata (incmingData)
Else
msgbox "Error: Not connected"
End If
-
Aug 12th, 2005, 06:25 AM
#13
Thread Starter
Fanatic Member
Re: Get ip address for the incoming client?
i mean server send out woh........??? server receive from client1 and send to client2........client2 doesnt doing socket listnen..........how?
-
Aug 12th, 2005, 01:08 PM
#14
Addicted Member
Re: Get ip address for the incoming client?
 Originally Posted by kenny_oh
i mean server send out woh........??? server receive from client1 and send to client2........client2 doesnt doing socket listnen..........how?
Ok, listen.. You would only need the server to listen. You would have to get the server to accept multiple connections, forget the code to do that.. but meh.. You have the server listen, and the clients connect and send the data through the server. Look around for information about how to allow multiple connections through one winsock. Sorry if I am not helping you exactly on what you need as I said I am new to winsock as well, I am slowly getting the hang of it.
Edit:
Add a Winsock control to your form and set its index to 0, then add this code into the server to allow multiple connections to it, I think this is write not to sure really..
VB Code:
Option Explicit
Public NumSockets As Integer
'//Public Variable to track number of Connections
Private Sub Form_Load()
Winsock1(0).LocalPort = 1066
Winsock1(0).Listen
End Sub
Private Sub Winsock1_Close(Index As Integer)
Winsock1(Index).Close
End Sub
Private Sub Winsock1_ConnectionRequest(Index As Integer, _
ByVal requestID As Long)
NumSockets = NumSockets + 1
'//Increase Number of Sockets by one.
Load Winsock1(NumSockets)
'//Load a New Winsock Object Numsockets as Index Value
Winsock1(NumSockets).Accept requestID
'//Accept the New Connection
End Sub
Private Sub Winsock1_DataArrival(Index As Integer, ByVal _
bytesTotal As Long)
Dim vtData As String
Winsock1(Index).GetData vtData, vbString
End Sub
Last edited by Jaquio; Aug 12th, 2005 at 03:31 PM.
-
Aug 14th, 2005, 09:47 AM
#15
New Member
Re: Get ip address for the incoming client?
an example to send your data to the client you want ....
client send something like:
VB Code:
winsock1.senddata(DataToSend & ":" & IP_Of_The_Other_Client)
then server recieve it:
VB Code:
Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Dim IPaddress
Winsock1(Index).GetData strData
IPaddress = split(strData, ":")
IPaddress = IPaddress(1)
'here comes the code to send the data to the other client ... it's IP is in IPaddress now...
End Sub
it's just an example code it's prolly not usefull as then u can't have the ":" in your data but as i said ... just an example
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|