I'd like to test a server application and a client application from
the same computer. Currently if I let the client try to connect to my
IPv4 adress provided by my router in this case 192.168.1.2 or my
"external" IP provided by my ISP the tcplistener in the Server class
wont accept the connection. Can I do this in another way and make it
work?
Server application source:
Imports System.Net.Sock ets
Imports System.Text
Public Class CServer
Const portNumber As Integer = 8000
Public tcpListener As New TcpListener(por tNumber)
Public tcpClient As New System.Net.Sock ets.TcpClient()
Public networkStream As NetworkStream
Public Function Connect() As Boolean
' Must listen on correct port- must be same as port client
wants to connect on.
Try
tcpListener.Sta rt()
' Console.WriteLi ne("Waiting for connection...")
Dim tcpClient As TcpClient = tcpListener.Acc eptTcpClient()
Catch e As Exception
Debug.Print("Fa iled to connect. " + e.Message)
Return False
End Try
Return True
End Function
Public Function Write(ByVal Message As String) As Boolean
Try
networkStream = tcpClient.GetSt ream()
Dim responseString As String = "Connected to server."
Dim sendBytes As [Byte]() =
Encoding.ASCII. GetBytes(respon seString)
networkStream.W rite(sendBytes, 0, sendBytes.Lengt h)
Console.WriteLi ne(("Message Sent /: " + responseString) )
'Any communication with the remote client using the
TcpClient can go here.
'Close TcpListener and TcpClient.
tcpClient.Close ()
tcpListener.Sto p()
Console.WriteLi ne("exit")
Console.ReadLin e()
Catch ex As Exception
End Try
End Function
End Class
' Calling Server class
Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim server As New CServer
server.Connect( )
server.Write("T est")
End Sub
End Class
Client application source:
Imports System.Net.Sock ets
Imports System.Text
Public Class CClient
Public tcpClient As System.Net.Sock ets.TcpClient
Public networkStream As NetworkStream
Public Function Connect(ByVal HostName As String) As Boolean
Try
tcpClient = New System.Net.Sock ets.TcpClient
tcpClient.Conne ct(HostName, 8000)
networkStream = tcpClient.GetSt ream()
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Function Read(ByRef ReadData As String) As Boolean
Try
If networkStream.C anRead Then
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
networkStream.R ead(bytes, 0,
CInt(tcpClient. ReceiveBufferSi ze))
' Output the data received from the host to the
console.
ReadData = Encoding.ASCII. GetString(bytes )
End If
' pause so user can view the console output
Console.ReadLin e()
Catch ex As Exception
Return False
End Try
Return True
End Function
End Class
'Calling client class
Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim client As New CClient
client.Connect( "192.168.1. 2")
Dim data As String
client.Read(Dat a)
End Sub
End Class 3 1595
"Joh" <me************ @hotmail.comwro te in message
news:11******** **************@ v3g2000hsg.goog legroups.com...
I'd like to test a server application and a client application from
the same computer. Currently if I let the client try to connect to my
IPv4 adress provided by my router in this case 192.168.1.2 or my
"external" IP provided by my ISP the tcplistener in the Server class
wont accept the connection. Can I do this in another way and make it
work?
You put the client on one machine on your LAN. You put the server on another
machine on the LAN. You set rules with the personal FW to open the ports
needed for the listening server machine or drop the PFW.
On Oct 31, 4:14 pm, Joh <meanmachine... @hotmail.comwro te:
I'd like to test a server application and a client application from
the same computer. Currently if I let the client try to connect to my
IPv4 adress provided by my router in this case 192.168.1.2 or my
"external" IP provided by my ISP the tcplistener in the Server class
wont accept the connection. Can I do this in another way and make it
work?
Server application source:
Imports System.Net.Sock ets
Imports System.Text
Public Class CServer
Const portNumber As Integer = 8000
Public tcpListener As New TcpListener(por tNumber)
Public tcpClient As New System.Net.Sock ets.TcpClient()
Public networkStream As NetworkStream
Public Function Connect() As Boolean
' Must listen on correct port- must be same as port client
wants to connect on.
Try
tcpListener.Sta rt()
' Console.WriteLi ne("Waiting for connection...")
Dim tcpClient As TcpClient = tcpListener.Acc eptTcpClient()
Catch e As Exception
Debug.Print("Fa iled to connect. " + e.Message)
Return False
End Try
Return True
End Function
Public Function Write(ByVal Message As String) As Boolean
Try
networkStream = tcpClient.GetSt ream()
Dim responseString As String = "Connected to server."
Dim sendBytes As [Byte]() =
Encoding.ASCII. GetBytes(respon seString)
networkStream.W rite(sendBytes, 0, sendBytes.Lengt h)
Console.WriteLi ne(("Message Sent /: " + responseString) )
'Any communication with the remote client using the
TcpClient can go here.
'Close TcpListener and TcpClient.
tcpClient.Close ()
tcpListener.Sto p()
Console.WriteLi ne("exit")
Console.ReadLin e()
Catch ex As Exception
End Try
End Function
End Class
' Calling Server class
Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim server As New CServer
server.Connect( )
server.Write("T est")
End Sub
End Class
Client application source:
Imports System.Net.Sock ets
Imports System.Text
Public Class CClient
Public tcpClient As System.Net.Sock ets.TcpClient
Public networkStream As NetworkStream
Public Function Connect(ByVal HostName As String) As Boolean
Try
tcpClient = New System.Net.Sock ets.TcpClient
tcpClient.Conne ct(HostName, 8000)
networkStream = tcpClient.GetSt ream()
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Function Read(ByRef ReadData As String) As Boolean
Try
If networkStream.C anRead Then
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
networkStream.R ead(bytes, 0,
CInt(tcpClient. ReceiveBufferSi ze))
' Output the data received from the host to the
console.
ReadData = Encoding.ASCII. GetString(bytes )
End If
' pause so user can view the console output
Console.ReadLin e()
Catch ex As Exception
Return False
End Try
Return True
End Function
End Class
'Calling client class
Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim client As New CClient
client.Connect( "192.168.1. 2")
Dim data As String
client.Read(Dat a)
End Sub
End Class
Do you have the firewall on?
--
Tom Shelton
On 1 Nov, 00:15, Tom Shelton <tom_shel...@co mcast.netwrote:
On Oct 31, 4:14 pm, Joh <meanmachine... @hotmail.comwro te:
I'd like to test a server application and a client application from
the same computer. Currently if I let the client try to connect to my
IPv4 adress provided by my router in this case 192.168.1.2 or my
"external" IP provided by my ISP the tcplistener in the Server class
wont accept the connection. Can I do this in another way and make it
work?
Server application source:
Imports System.Net.Sock ets
Imports System.Text
Public Class CServer
Const portNumber As Integer = 8000
Public tcpListener As New TcpListener(por tNumber)
Public tcpClient As New System.Net.Sock ets.TcpClient()
Public networkStream As NetworkStream
Public Function Connect() As Boolean
' Must listen on correct port- must be same as port client
wants to connect on.
Try
tcpListener.Sta rt()
' Console.WriteLi ne("Waiting for connection...")
Dim tcpClient As TcpClient = tcpListener.Acc eptTcpClient()
Catch e As Exception
Debug.Print("Fa iled to connect. " + e.Message)
Return False
End Try
Return True
End Function
Public Function Write(ByVal Message As String) As Boolean
Try
networkStream = tcpClient.GetSt ream()
Dim responseString As String = "Connected to server."
Dim sendBytes As [Byte]() =
Encoding.ASCII. GetBytes(respon seString)
networkStream.W rite(sendBytes, 0, sendBytes.Lengt h)
Console.WriteLi ne(("Message Sent /: " + responseString) )
'Any communication with the remote client using the
TcpClient can go here.
'Close TcpListener and TcpClient.
tcpClient.Close ()
tcpListener.Sto p()
Console.WriteLi ne("exit")
Console.ReadLin e()
Catch ex As Exception
End Try
End Function
End Class
' Calling Server class
Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim server As New CServer
server.Connect( )
server.Write("T est")
End Sub
End Class
Client application source:
Imports System.Net.Sock ets
Imports System.Text
Public Class CClient
Public tcpClient As System.Net.Sock ets.TcpClient
Public networkStream As NetworkStream
Public Function Connect(ByVal HostName As String) As Boolean
Try
tcpClient = New System.Net.Sock ets.TcpClient
tcpClient.Conne ct(HostName, 8000)
networkStream = tcpClient.GetSt ream()
Catch ex As Exception
Return False
End Try
Return True
End Function
Public Function Read(ByRef ReadData As String) As Boolean
Try
If networkStream.C anRead Then
' Read the NetworkStream into a byte buffer.
Dim bytes(tcpClient .ReceiveBufferS ize) As Byte
networkStream.R ead(bytes, 0,
CInt(tcpClient. ReceiveBufferSi ze))
' Output the data received from the host to the
console.
ReadData = Encoding.ASCII. GetString(bytes )
End If
' pause so user can view the console output
Console.ReadLin e()
Catch ex As Exception
Return False
End Try
Return True
End Function
End Class
'Calling client class
Public Class Form1
Private Sub Form1_Load(ByVa l sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Load
Dim client As New CClient
client.Connect( "192.168.1. 2")
Dim data As String
client.Read(Dat a)
End Sub
End Class
Do you have the firewall on?
--
Tom Shelton- Dölj citerad text -
- Visa citerad text -
Hi Tom,
Yes, I have a firewall on my router and Windows firewall. I shut down
the Wíndows firewall but still can't connect. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike MacSween |
last post by:
I've got a SQL Server database. Nearly finished. It's going to go on a
single non networked machine. One day somebody might get access to it over
ADSL (probably TS), but for now it's a single user no lan.
The machine will actually be running the MSDE. Windows XP Home.
I'm quite happy, for now, to put all the business logic in SQL Server.
Triggers, SPs etc.
I've got a fair bit of Access development experience.
|
by: Ken Allen |
last post by:
Most of .Net seems to be focused on the concept of multiple clients and a
single server that provides the control. All of the examples that I have
seen presume that the client code knows the computer system on which the
server component resides.
1. If the client does not know the name of the computer system, how can it
locate that system?
2. If there are two or more computer systems all making the same server
component available (even...
|
by: Naveen Mukkelli |
last post by:
Hi,
I'm writing a client/server application using C#.
The server accepts connecitons asynchronously, using BeginAccept/EndAccept.
Is there any way we can write some unit tests(NUnit) to test the behaviour
of
accepting connections and testing some other private methods that would be
called when the server receives a connection request.
|
by: wrytat |
last post by:
I'm not sure if I'm posting the correct place. I posted it somewhere else,
but someone told me to post it at another place.
Anyway, some background first. I am currently building a web application for
my company. This application is going to be hosted with an ISP on a shared
server. And my company doesn't have a static IP.
I want to make part of my web application such that only my company's
computer can access (something like an...
|
by: B1ackwater |
last post by:
We've fooled around with Access a bit, but only using the
single-user store-bought version. It seems to be a good
database - versatile and infinitely programmable - and
can apparently be used as a front end to SQL server if
we ever needed to go that route.
But - is there a client/server version of Access ? Looking
on the CDW site there is a bewildering variety of packages
and licences and such, but we can't figure out just which
do...
| |
by: WhatHappend |
last post by:
I have converted a .Net 1.0 application to .Net 2.0 and the web service
invocations have delay of around 10seconds on each intial access. After the
first access subsequent access are fast (After a whild of inactivity the next
access will be slow agian). Changing the client to static IP address instead
of DHCP makes the initial access about 1 second which is fine.
Monitoring the network of the client computer the cleint is sending out 2...
|
by: Wimpie van Lingen |
last post by:
Hey
I have some more questions with regards to Remoting in .NET 2. I'm using TCP with the Binary formatter.
My solution consists of 4 projects:
- Class Library containing the server classes which Inherits MarshalByRefObject (ok, at this stage it only contains one class... but its gonna grow)
- Class Library containing common classes and interfaces that will be shared between all projects. This include interfaces for the server...
|
by: Dan Rumney |
last post by:
Hi all,
I've been writing Javascript for quite a while now and have, of late,
been writing quite a lot of AJAX and AJAX-related code.
In the main, my dynamically generated pages are created using Perl on
the backend, with Javascript providing limited frontend functionality.
As an example, an expanding tree would be fully populated on the
server-side and then presented to the browser, with Javascript and CSS
being used to vary the...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |