473,395 Members | 1,968 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,395 software developers and data experts.

Convert Vb socket to C#

Hello. I have a problem. I have code in VB, socket based code that i need to convert in winsock of C# express edition, but i don't know how to use winsock control in C# exactly, it return errors. can anyone help me?

here is the VB Code:
Expand|Select|Wrap|Line Numbers
  1. Private Sub socket_Connect()
  2. dim abc as string
  3.   abc = "UserName=" & nick() & "&Password=" & Pass & "&UserID=" & Uid & Text1.Text & "&mode=User"
  4.     socket.SendData ("POST " & "http://" & "myweb.com" & "/showlogin" & " HTTP/1.1" & vbCrLf & _
  5.         "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, */*" & vbCrLf & _
  6.         "Referer: http://www.myweb.com/file.php" & vbCrLf & _
  7.         "Accept-Language: en-us" & vbCrLf & _
  8.         "Content-Type: application/x-www-form-urlencoded" & vbCrLf & _
  9.         "Accept-Encoding: gzip, deflate" & vbCrLf & _
  10.         "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)" & vbCrLf & _
  11.         "Host: " & "myweb.com & ":80" & vbCrLf & _
  12.         "Content-Length: " & Len(abc) & vbCrLf & _
  13.         "Connection: Keep-Alive" & vbCrLf & vbCrLf & _
  14.         abc & vbCrLf)
  15. End Sub
Thanx a lot
Sep 11 '08 #1
5 1514
Plater
7,872 Expert 4TB
You should be using the Socket object (or possibly TcpListener / TcpClient, depending on how much wrapping you want)
winsock was an old vb control that they did away with.
Sep 11 '08 #2
I understand but all the ways i treid to convert this code in C# it gives me errors, especifically here:

Expand|Select|Wrap|Line Numbers
  1. "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, */*";
  2. "Referer: http://www.myweb.com/file.php";
  3. "Accept-Language: en-us";
  4. "Content-Type: application/x-www-form-urlencoded";
  5. "Accept-Encoding: gzip, deflate";
  6. "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)";
  7. "Host: " + "myweb.com + ":80";
  8. "Content-Length: " & abc.Lenght;
  9. "Connection: Keep-Alive";
i don't understand where i have to put this line of code in socket of C#.
Sep 11 '08 #3
For example, i have php file on my server, and from C# i want to post there. I know how to di it in VB but i don't know how do it in C#. Anyone can help me?
here is the full Code of VB shouting:
Expand|Select|Wrap|Line Numbers
  1. Dim abc As String
  2. Private Sub Command1_Click()
  3. Winsock2.Close
  4. Winsock2.Connect "host.com", 80
  5. End Sub
  6. Private Sub Winsock2_Connect()
  7. abc = "&name=" & Me.Text1.Text & "&shoutbox=" & Me.Text2.Text & "&submit=Send"
  8.     Winsock2.SendData ("POST /user/subfolder/shoutbox.php?action=shoutbox HTTP/1.1" & vbCrLf & _
  9.         "Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/msword, */*" & vbCrLf & _
  10.         "Accept-Language: en-us" & vbCrLf & _
  11.         "Content-Type: application/x-www-form-urlencoded" & vbCrLf & _
  12.         "Accept-Encoding: gzip, deflate" & vbCrLf & _
  13.         "User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows 98; Win 9x 4.90)" & vbCrLf & _
  14.         "Host: " & "myhost.com" & ":80" & vbCrLf & _
  15.         "Content-Length: " & Len(abc) & vbCrLf & _
  16.         "Connection: Keep-Alive" & vbCrLf & vbCrLf & _
  17.          abc & vbCrLf)
  18.          End Sub
Im trieng to do this in C# but i'm getting errors.
Sep 11 '08 #4
Plater
7,872 Expert 4TB
Well those are all strings that you could send down the Socket to the php page.
For that situation though it might be better to use the HttpWebRequest object, since it was designed to make those type of socket calls.
Sep 11 '08 #5
Curtis Rutland
3,256 Expert 2GB
Please start using [code] tags when you post code. This isn't optional, it is a requirement.

I've fixed these posts.

MODERATOR
Sep 11 '08 #6

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

Similar topics

1
by: OZ | last post by:
the serproxy claim itself a multi-thread proxy thing. I have sent email to write the original writer and there is no replay after 3 weeks. my configuration and setting are good. ...
6
by: Gator | last post by:
Hi All, Basically my situation is this, I have a server implemented in C++, unmanaged code, using proprietery protocol over TCP/IP to communicate with the cilent(c++ also). Now, I am implementing...
7
by: Prabhu | last post by:
Hi, I have to send a structure through TCPClient socket. we can send only byte array through the socket, So please any one can help me by telling How to convert a struct object into an byte...
1
by: Jim | last post by:
Here is a snipet of the code. // State object for receiving data from remote device. public class StateObject { // Client socket. public Socket workSocket = null; // Size of receive buffer....
6
by: Ricardo Quintanilla | last post by:
i have a code that sends data to a socket listening over as400 platform, the socket responds to me as a "byte array". then i need to convert the "byte array" into a string. the problem is that...
1
by: Sergey Muschin | last post by:
Hi there, i need to send a socket message to TCP socket server. Server has been implemented with VC 6.0 and expects from client the message in this format typedef struct { int msg_nbr; ...
13
by: kbperry | last post by:
Hi all, Background: I need some help. I am trying to streamline a process for one of our technical writers. He is using Perforce (version control system), and is constantly changing his word...
1
by: mangala | last post by:
i hav gotta convert an int array to a char array.. so that i can write it to the socket.. that is in the server side.. n in the client side i gotta read d socket... get d char array n convert it...
3
by: Jonathan | last post by:
I have taken up C++ programming again and need to write a socket client, so far I am able to create the connection to the socket. As I need a unix timestamp in char to put on a socket in a HTTP...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
marktang
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,...
0
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...
0
Oralloy
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,...
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...

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.