473,411 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,411 software developers and data experts.

Socket programming

hi team,

Am doing socket programming in vb.net. I have used client side program in window application and for server side it was console application. Application is running fine. but when send the data from client side, it was got displayed in server end and server was getting closed. i cant able to get where it was hiking up. please help me.

Client side program
Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.data
  3. Imports System.Net.Sockets
  4.  
  5. Public Class Form1
  6.     Dim serverlistener As New TcpClient("localhost", 8585)
  7.     Dim readstream As Stream = serverlistener.GetStream()
  8.  
  9.     Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
  10.  
  11.         Try
  12.             serverlistener.SendBufferSize = 256
  13.             Dim str As String
  14.             str = TextBox1.Text
  15.             While str <> ""
  16.                 Dim sendbuff As Byte() = System.Text.Encoding.ASCII.GetBytes(str)
  17.                 readstream.Write(sendbuff, 0, sendbuff.Length)
  18.  
  19.             End While
  20.         Catch ex As Exception
  21.  
  22.         End Try
  23.  
  24.  
  25.     End Sub
  26.  
  27.  
  28. End Class
Server Side
Expand|Select|Wrap|Line Numbers
  1. Imports System.IO
  2. Imports System.Net.Sockets
  3.  
  4. Module Module1
  5.  
  6.     Sub Main()
  7.         Try
  8.             Dim clientlistener As New TcpListener(8585)
  9.             clientlistener.Start()
  10.             Console.WriteLine("")
  11.             Dim mysocket As Socket = clientlistener.AcceptSocket
  12.             Console.WriteLine("")
  13.             Dim writebyte(225) As Byte
  14.             mysocket.Receive(writebyte, writebyte.Length, SocketFlags.None)
  15.             Dim str As String = System.Text.Encoding.ASCII.GetString(writebyte, 0, writebyte.Length).Trim(Microsoft.VisualBasic.ChrW(0))
  16.             Dim i As Integer
  17.             For i = 0 To str.Length
  18.                 Console.WriteLine(str)
  19.                 'mysocket.Receive(writebyte, writebyte.Length, SocketFlags.None)
  20.                 ' str = System.Text.Encoding.ASCII.GetString(writebyte, 0, writebyte.Length).Trim(Microsoft.VisualBasic.ChrW(0))
  21.  
  22.             Next
  23.             'While Not str.StartsWith(".")
  24.  
  25.             '    mysocket.Receive(writebyte, writebyte.Length, SocketFlags.None)
  26.             '    str = System.Text.Encoding.ASCII.GetString(writebyte, 0, writebyte.Length).Trim(Microsoft.VisualBasic.ChrW(0))
  27.  
  28.             'End While
  29.             'Console.WriteLine(str)
  30.  
  31.         Catch ex As Exception
  32.  
  33.         End Try
  34.  
  35.         'Console.Write(str)
  36.  
  37.  
  38.     End Sub
  39.  
  40. End Module
  41.  
Jul 1 '10 #1
0 1299

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Rob | last post by:
Hello, I've got a huge problem with async sockets. I've created a networked virtual environment, using async socket programming. The problem I face occurs when I close the listener socket. It...
2
by: Jean-Philippe Guyon | last post by:
Hello, I am trying to compile a class that uses socket using the Visual C++ ..NET compiler. I get the following error: ------ Build started: Project: infCommon, Configuration: Release Win32...
4
by: Ted | last post by:
Hi all, I am trying to learn C socket programming and I have a small program which is a UP client. The problem is, when I run the program, I get a runtime error - "Invalid Argument" - from a...
2
by: chellappa | last post by:
Hi Every body!, i did a small Chat program in Linux C Socket Programm ... I am using stdout/stdin i did in single machinee i will work properly..but i want to run in differnet machine..i tried...
5
by: John Sheppard | last post by:
Hi all, I am not sure that I am posting this in the right group but here it goes anyway. I am new to socket programming and I have been searching on the internet to the questions I am about to pose...
1
by: John Sheppard | last post by:
Thanks to everyone that responded to my previous Socket Programming question. Now I have run into some behavior that I don't quite understand. Programming environment. VS.NET 2003, C#, Windows...
9
by: Michael Lindsey | last post by:
I need to write a server app to send images to client GUIs that are outside of the server's domain. The client will have the file system path to the image but can not access the file system. I am...
4
by: Marco Meoni | last post by:
Hi. I read the Gordon McMillan's "Socket Programming Howto". I tried to use the example in this howto but this doesn't work. The code is class mysocket: '''classe solamente dimostrativa -...
8
by: =?Utf-8?B?Sm9obg==?= | last post by:
Hi all, I am new to .net technologies. ASP.NET supports socket programming like send/receive in c or c++? I am developing web-site application in asp.net and code behind is Visual C#. In...
1
by: phpuser123 | last post by:
I just started socket programming in java.I read a few tutorial and came up with the following script import java.net.*; public class socket { /** * @param args */ public static...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.