Hi, I'm able to make connection to a server using socket connection.
However, when I send a command string the server just ignores it. All
command string needs to start with "0xF9" at Byte 0. During the run-time
debug, I see it to be "u" with a "~" on top of it. Is that OxF9? Can
someone tell me what I'm doing wrong?
Thanks, Alpha
private void Connect(String server, String message)
{
//Socket Connect
try
{
//create a new client socket ...
m_socClient = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am,
ProtocolType.Tc p);
String szIPSelected = "192.168.1. 7";
String szPort = "22333";
int alPort = System.Convert. ToInt16 (szPort,10);
System.Net.IPAd dress remoteIPAddress =
System.Net.IPAd dress.Parse(szI PSelected);
System.Net.IPEn dPoint remoteEndPoint = new
System.Net.IPEn dPoint(remoteIP Address, alPort);
m_socClient.Con nect(remoteEndP oint);
// String message = "Hello There";
// byte[] byData = System.Text.Enc oding.ASCII.Get Bytes(message);
// m_socClient.Sen d(byData);
}
catch (SocketExceptio n se)
{
MessageBox.Show ( se.Message );
}
//Send ATS Data
try
{
byte[] byData = System.Text.Enc oding.ASCII.Get Bytes(message);
m_socClient.Sen d (byData);
}
catch(SocketExc eption se)
{
MessageBox.Show (se.Message );
}
//Receive ATS Data
// Receive the TcpServer.respo nse.
try
{
byte [] buffer = new byte[256];
int iRx = m_socClient.Rec eive (buffer);
char[] chars = new char[iRx];
System.Text.Dec oder d = System.Text.Enc oding.UTF8.GetD ecoder();
int charLen = d.GetChars(buff er, 0, iRx, chars, 0);
System.String Retmessage = new System.String(c hars);
MessageBox.Show ("Reply from ATS server: "+ Retmessage.ToSt ring() ,
"ATS Reply", MessageBoxButto ns.OK, MessageBoxIcon. Information);
}
catch(SocketExc eption se)
{
MessageBox.Show (se.Message );
}
//Close Socket Connection
m_socClient.Clo se ();
}
private void menuItem9_Click (object sender, System.EventArg s e)
{
string Message;
Message = "\xF9" + "1800000007CATT ,TO";
Connect("Map", Message);
} 2 5285
Alpha,
0xF9 is definitely not in the ASCII character set, so it's very possible
that the character you see is correct. However, this doesn't mean that what
you are sending is wrong. It just is that the "u" character is the
representation of that byte. However, how the service interprets it is
completely irrelevant.
If you actually want to send the byte F9, then do not send it as a
string. Rather, create the byte array with this value yourself, and send
that.
Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"Alpha" <Al***@discussi ons.microsoft.c om> wrote in message
news:9E******** *************** ***********@mic rosoft.com... Hi, I'm able to make connection to a server using socket connection. However, when I send a command string the server just ignores it. All command string needs to start with "0xF9" at Byte 0. During the run-time debug, I see it to be "u" with a "~" on top of it. Is that OxF9? Can someone tell me what I'm doing wrong? Thanks, Alpha
private void Connect(String server, String message) { //Socket Connect try { //create a new client socket ... m_socClient = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am, ProtocolType.Tc p); String szIPSelected = "192.168.1. 7"; String szPort = "22333"; int alPort = System.Convert. ToInt16 (szPort,10);
System.Net.IPAd dress remoteIPAddress = System.Net.IPAd dress.Parse(szI PSelected); System.Net.IPEn dPoint remoteEndPoint = new System.Net.IPEn dPoint(remoteIP Address, alPort); m_socClient.Con nect(remoteEndP oint); // String message = "Hello There"; // byte[] byData = System.Text.Enc oding.ASCII.Get Bytes(message); // m_socClient.Sen d(byData);
} catch (SocketExceptio n se) { MessageBox.Show ( se.Message ); }
//Send ATS Data try { byte[] byData = System.Text.Enc oding.ASCII.Get Bytes(message); m_socClient.Sen d (byData); } catch(SocketExc eption se) { MessageBox.Show (se.Message ); }
//Receive ATS Data // Receive the TcpServer.respo nse.
try { byte [] buffer = new byte[256]; int iRx = m_socClient.Rec eive (buffer); char[] chars = new char[iRx];
System.Text.Dec oder d = System.Text.Enc oding.UTF8.GetD ecoder(); int charLen = d.GetChars(buff er, 0, iRx, chars, 0); System.String Retmessage = new System.String(c hars); MessageBox.Show ("Reply from ATS server: "+ Retmessage.ToSt ring() , "ATS Reply", MessageBoxButto ns.OK, MessageBoxIcon. Information); } catch(SocketExc eption se) { MessageBox.Show (se.Message ); }
//Close Socket Connection m_socClient.Clo se ();
}
private void menuItem9_Click (object sender, System.EventArg s e) { string Message; Message = "\xF9" + "1800000007CATT ,TO";
Connect("Map", Message); }
Thank you Nicholas for the help. Can you show me how to send F9 and the rest
of my message in the bye array?
Thanks, Alpha
"Nicholas Paldino [.NET/C# MVP]" wrote: Alpha,
0xF9 is definitely not in the ASCII character set, so it's very possible that the character you see is correct. However, this doesn't mean that what you are sending is wrong. It just is that the "u" character is the representation of that byte. However, how the service interprets it is completely irrelevant.
If you actually want to send the byte F9, then do not send it as a string. Rather, create the byte array with this value yourself, and send that.
Hope this helps.
-- - Nicholas Paldino [.NET/C# MVP] - mv*@spam.guard. caspershouse.co m
"Alpha" <Al***@discussi ons.microsoft.c om> wrote in message news:9E******** *************** ***********@mic rosoft.com... Hi, I'm able to make connection to a server using socket connection. However, when I send a command string the server just ignores it. All command string needs to start with "0xF9" at Byte 0. During the run-time debug, I see it to be "u" with a "~" on top of it. Is that OxF9? Can someone tell me what I'm doing wrong? Thanks, Alpha
private void Connect(String server, String message) { //Socket Connect try { //create a new client socket ... m_socClient = new Socket(AddressF amily.InterNetw ork, SocketType.Stre am, ProtocolType.Tc p); String szIPSelected = "192.168.1. 7"; String szPort = "22333"; int alPort = System.Convert. ToInt16 (szPort,10);
System.Net.IPAd dress remoteIPAddress = System.Net.IPAd dress.Parse(szI PSelected); System.Net.IPEn dPoint remoteEndPoint = new System.Net.IPEn dPoint(remoteIP Address, alPort); m_socClient.Con nect(remoteEndP oint); // String message = "Hello There"; // byte[] byData = System.Text.Enc oding.ASCII.Get Bytes(message); // m_socClient.Sen d(byData);
} catch (SocketExceptio n se) { MessageBox.Show ( se.Message ); }
//Send ATS Data try { byte[] byData = System.Text.Enc oding.ASCII.Get Bytes(message); m_socClient.Sen d (byData); } catch(SocketExc eption se) { MessageBox.Show (se.Message ); }
//Receive ATS Data // Receive the TcpServer.respo nse.
try { byte [] buffer = new byte[256]; int iRx = m_socClient.Rec eive (buffer); char[] chars = new char[iRx];
System.Text.Dec oder d = System.Text.Enc oding.UTF8.GetD ecoder(); int charLen = d.GetChars(buff er, 0, iRx, chars, 0); System.String Retmessage = new System.String(c hars); MessageBox.Show ("Reply from ATS server: "+ Retmessage.ToSt ring() , "ATS Reply", MessageBoxButto ns.OK, MessageBoxIcon. Information); } catch(SocketExc eption se) { MessageBox.Show (se.Message ); }
//Close Socket Connection m_socClient.Clo se ();
}
private void menuItem9_Click (object sender, System.EventArg s e) { string Message; Message = "\xF9" + "1800000007CATT ,TO";
Connect("Map", Message); } This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jeff Crouse |
last post by:
In my project, I have successfully opened a sock_stream style socket
connection between two processes and am trying to send 'buffer' to a
connected client, 'fd'.
The following code works just fine.
void Macsock::writeData(char *buffer, int fd)
{
char message = "This is a message from the front.";
if(write(fd, message, sizeof(message)) < 0 )
|
by: Lynne |
last post by:
I am using the C# asynchronous socket functionality for a server, and
it appears to work fine if I just receive data and echo it back to the
client. The problem occurs when I try to handle sending data
independent of a receive. The send happens just fine, but when I
receive the next set of data from the client (in a size, size, data
set of packets), I lose however many packets of data I sent. For
example, a normal client send would...
|
by: Abhishek |
last post by:
I have a problem transfering files using sockets from pocket pc(.net compact
c#) to desktop(not using .net just mfc and sockets 2 API). The socket
communication is not a issue and I am able to transfer data across.On the
serve I am using Socket 2 API (recv function to read bytes)and not using
..NET. I use FileStream to open the file on the pocket pc, then associate a
BinaryReader object with the stream and call ReadBytes to read all the...
|
by: Droopy |
last post by:
Hi,
I try to implement a reusable socket class to send and receive data.
It seems to work but I have 2 problems :
1) I rely on Socket.Available to detect that the connection is closed (no
more data to expect). Sometimes, Socket.Available returns 0 but the other
end of the connection did not close it !
2) This class will be used by many other classes so I have to use the
|
by: yaron |
last post by:
Hi,
I have a problem when sending data over TCP socket from c# client to java
server.
the connection established ok, but i can't send data from c# client to java
server.
it's work ok with TcpClient, NetworkStream and StreamWriter classes.
but with low level socket it doesn't work (When using the Socket class Send
method).
| |
by: zaebos |
last post by:
hi, i have this code which is part of a main program, to email from
within the program a log file:
int MailIt (char *mailserver, char *emailto, char *emailfrom,
char *emailsubject, char *emailmessage) {
SOCKET sockfd;
WSADATA wsaData;
FILE *smtpfile;
#define bufsize 300
|
by: BuddyWork |
last post by:
Hello,
Could someone please explain why the Socket.Send is slow to send to the same
process it sending from. Eg. Process1 calls Socket.Send which sends to the
same IP address and port, the receiver is running within Process1.
If I move the receiver into Process2 then its fast.
Please can someone explain.
|
by: Buddy Home |
last post by:
There is two examples of code.
Example 1. Send and Receive within the same process. Put this code in a
console app called SendAndReceive and run the code.
using System;
using System.Collections.Generic;
using System.Net;
using System.Net.Sockets;
using System.Runtime.Serialization.Formatters.Binary;
|
by: Danny |
last post by:
Hi all,
Trying to send mail with System.Net.SmtpClient, using very simple code
just for testing:
SmtpClient smtp = new SmtpClient("mail.server.com", 25);
smtp.Credentials = new
System.Net.NetworkCredential("user", "password");
try
{
|
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: 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: 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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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: 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 then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
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: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |